sonata-project / SonataAdminBundle

The missing Symfony Admin Generator
https://docs.sonata-project.org/projects/SonataAdminBundle
MIT License
2.11k stars 1.26k forks source link

Sonata causes some TWIG parent() calls to fail #8181

Closed TomasLudvik closed 1 week ago

TomasLudvik commented 6 months ago

Environment

Sonata packages

show

``` $ composer show --latest 'sonata-project/*' Direct dependencies required in composer.json: sonata-project/admin-bundle 4.30.2 4.30.2 The missing Symfony Admin Generator sonata-project/doctrine-orm-admin-bundle 4.17.1 4.17.1 Integrate Doctrine ORM into the SonataAdminBundle Transitive dependencies not required in composer.json: sonata-project/block-bundle 5.1.0 5.1.0 Symfony SonataBlockBundle sonata-project/doctrine-extensions 2.4.0 2.4.0 Doctrine2 behavioral extensions sonata-project/exporter 3.3.0 3.3.0 Lightweight Exporter library sonata-project/form-extensions 2.4.0 2.4.0 Symfony form extensions sonata-project/twig-extensions 2.4.0 2.4.0 Sonata twig extensions ```

Symfony packages

show

``` $ composer show --latest 'symfony/*' Direct dependencies required in composer.json: symfony/browser-kit 5.4.39 7.0.7 Simulates the behavior of a web browser, allowing you to make requests, click on links and submit forms programmatically symfony/css-selector 5.4.39 7.0.7 Converts CSS selectors to XPath expressions symfony/debug-bundle 5.4.39 7.0.7 Provides a tight integration of the Symfony VarDumper component and the ServerLogCommand from MonologBridge into the Symfony full-stack framework symfony/dom-crawler 5.4.39 7.0.7 Eases DOM navigation for HTML and XML documents symfony/dotenv 5.4.39 7.0.7 Registers environment variables from a .env file symfony/error-handler 5.4.39 7.0.7 Provides tools to manage errors and ease debugging PHP code symfony/event-dispatcher 5.4.39 7.0.7 Provides tools that allow your application components to communicate with each other by dispatching events and listening to them symfony/flex 1.21.6 2.4.5 Composer plugin for Symfony symfony/form 5.4.39 7.0.7 Allows to easily create, process and reuse HTML forms symfony/html-sanitizer 6.4.7 7.0.7 Provides an object-oriented API to sanitize untrusted HTML input for safe insertion into a document's DOM. symfony/http-client 5.4.39 7.0.7 Provides powerful methods to fetch HTTP resources synchronously or asynchronously symfony/mailer 5.4.39 7.0.7 Helps sending emails symfony/messenger 5.4.39 7.0.7 Helps applications send and receive messages to/from other applications or via message queues symfony/monolog-bridge 5.4.39 7.0.7 Provides integration for Monolog with various Symfony components symfony/monolog-bundle 3.10.0 3.10.0 Symfony MonologBundle symfony/property-info 5.4.39 7.0.7 Extracts information about PHP class' properties using metadata of popular sources symfony/proxy-manager-bridge 5.4.39 6.4.7 Provides integration for ProxyManager with various Symfony components symfony/rate-limiter 5.4.39 7.0.7 Provides a Token Bucket implementation to rate limit input and output in your application symfony/runtime 5.4.39 7.0.7 Enables decoupling PHP applications from global state symfony/security-bundle 5.4.39 7.0.7 Provides a tight integration of the Security component into the Symfony full-stack framework symfony/service-contracts 2.5.3 3.5.0 Generic abstractions related to writing services symfony/stopwatch 5.4.39 7.0.7 Provides a way to profile code symfony/translation 5.4.39 7.0.7 Provides tools to internationalize your application symfony/twig-bundle 5.4.39 7.0.7 Provides a tight integration of Twig into the Symfony full-stack framework symfony/validator 5.4.39 7.0.7 Provides tools to validate values symfony/var-dumper 5.4.39 7.0.7 Provides mechanisms for walking through any arbitrary PHP variable symfony/web-link 5.4.39 7.0.7 Manages links between resources symfony/web-profiler-bundle 5.4.39 7.0.7 Provides a development tool that gives detailed information about the execution of any request symfony/webpack-encore-bundle 1.17.2 2.1.1 Integration with your Symfony app & Webpack Encore! symfony/workflow 5.4.39 7.0.7 Provides tools for managing a workflow or finite state machine Transitive dependencies not required in composer.json: symfony/amqp-messenger 5.4.39 7.0.7 Symfony AMQP extension Messenger Bridge symfony/asset 5.4.39 7.0.7 Manages URL generation and versioning of web assets such as CSS stylesheets, JavaScript files and image files symfony/cache 5.4.39 7.0.7 Provides extended PSR-6, PSR-16 (and tags) implementations symfony/cache-contracts 2.5.3 3.5.0 Generic abstractions related to caching symfony/config 5.4.39 7.0.7 Helps you find, load, combine, autofill and validate configuration values of any kind symfony/console 5.4.39 7.0.7 Eases the creation of beautiful and testable command line interfaces symfony/dependency-injection 5.4.39 7.0.7 Allows you to standardize and centralize the way objects are constructed in your application symfony/deprecation-contracts 3.5.0 3.5.0 A generic function and convention to trigger deprecation notices symfony/doctrine-bridge 5.4.39 7.0.7 Provides integration for Doctrine with various Symfony components symfony/doctrine-messenger 5.4.39 7.0.7 Symfony Doctrine Messenger Bridge symfony/event-dispatcher-contracts 3.5.0 3.5.0 Generic abstractions related to dispatching event symfony/expression-language 5.4.39 7.0.7 Provides an engine that can compile and evaluate expressions symfony/filesystem 5.4.39 7.0.7 Provides basic utilities for the filesystem symfony/finder 5.4.39 7.0.7 Finds files and directories via an intuitive fluent interface symfony/framework-bundle 5.4.39 7.0.7 Provides a tight integration between Symfony components and the Symfony full-stack framework symfony/http-client-contracts 2.5.3 3.5.0 Generic abstractions related to HTTP clients symfony/http-foundation 5.4.39 7.0.7 Defines an object-oriented layer for the HTTP specification symfony/http-kernel 5.4.39 7.0.7 Provides a structured process for converting a Request into a Response symfony/lock 5.4.39 7.0.7 Creates and manages locks, a mechanism to provide exclusive access to a shared resource symfony/mime 5.4.39 7.0.7 Allows manipulating MIME messages symfony/options-resolver 5.4.39 7.0.7 Provides an improved replacement for the array_replace PHP function symfony/password-hasher 5.4.39 7.0.7 Provides password hashing utilities symfony/polyfill-ctype 1.29.0 1.29.0 Symfony polyfill for ctype functions symfony/polyfill-intl-grapheme 1.29.0 1.29.0 Symfony polyfill for intl's grapheme_* functions symfony/polyfill-intl-icu 1.29.0 1.29.0 Symfony polyfill for intl's ICU-related data and classes symfony/polyfill-intl-idn 1.29.0 1.29.0 Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions symfony/polyfill-intl-normalizer 1.29.0 1.29.0 Symfony polyfill for intl's Normalizer class and related functions symfony/polyfill-mbstring 1.29.0 1.29.0 Symfony polyfill for the Mbstring extension symfony/polyfill-php72 1.29.0 1.29.0 Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions symfony/polyfill-php73 1.29.0 1.29.0 Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions symfony/polyfill-php80 1.29.0 1.29.0 Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions symfony/polyfill-php81 1.29.0 1.29.0 Symfony polyfill backporting some PHP 8.1+ features to lower PHP versions symfony/process 5.4.39 7.0.7 Executes commands in sub-processes symfony/property-access 5.4.39 7.0.7 Provides functions to read and write from/to an object or array using a simple string notation symfony/psr-http-message-bridge 2.3.1 7.0.7 PSR HTTP message bridge symfony/redis-messenger 5.4.39 7.0.7 Symfony Redis extension Messenger Bridge symfony/routing 5.4.39 7.0.7 Maps an HTTP request to a set of configuration variables symfony/security-acl 3.3.3 3.3.3 Symfony Security Component - ACL (Access Control List) symfony/security-core 5.4.39 7.0.7 Symfony Security Component - Core Library symfony/security-csrf 5.4.39 7.0.7 Symfony Security Component - CSRF Library symfony/security-guard 5.4.39 5.4.39 Symfony Security Component - Guard symfony/security-http 5.4.39 7.0.7 Symfony Security Component - HTTP Integration symfony/serializer 5.4.39 7.0.7 Handles serializing and deserializing data structures, including object graphs, into array structures or other formats like XML and JSON. symfony/string 5.4.39 7.0.7 Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a unified way symfony/translation-contracts 2.5.3 3.5.0 Generic abstractions related to translation symfony/twig-bridge 5.4.39 7.0.7 Provides integration for Twig with various Symfony components symfony/var-exporter 6.4.7 7.0.7 Allows exporting any serializable PHP data structure to plain PHP code symfony/yaml 5.4.39 7.0.7 Loads and dumps YAML files ```

PHP version

$ php -v
PHP 8.3.6 (cli) (built: Apr 24 2024 05:34:41) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.6, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.6, Copyright (c), by Zend Technologies

Subject

I have installed Sonata into my project and it is working fine, but it caused some parent() calls in TWIG to fail on An exception has been thrown during the rendering of a template ("Warning: Array to string conversion").. I have tried to debug this, until I got to this line in TWIG, where TWIG expects a string, but is given this array:

array:8 [▼
  "name" => false
  "admin" => false
  "value" => null
  "edit" => "standard"
  "inline" => "natural"
  "field_description" => null
  "block_name" => false
  "options" => array:26 [▼
    "default_group" => "Orders"
    "html5_validate" => true
    "sort_admins" => false
    "confirm_exit" => true
    "js_debug" => false
    "skin" => "skin-black"
    "use_select2" => true
    "use_icheck" => true
    "use_bootlint" => false
    "use_stickyforms" => true
    "pager_links" => null
    "form_type" => "standard"
    "default_admin_route" => "show"
    "default_label_catalogue" => "SonataAdminBundle"
    "default_translation_domain" => null
    "default_icon" => "fas fa-folder"
    "dropdown_number_groups_per_colums" => 2
    "logo_content" => "all"
    "list_action_button_content" => "all"
    "lock_protection" => false
    "mosaic_background" => "bundles/sonataadmin/images/default_mosaic_image.png"
    "javascripts" => array:3 [▼
      0 => "bundles/sonataadmin/app.js"
      1 => "bundles/sonataform/app.js"
      2 => "bundles/shopsysadmin/js/admin.js"
    ]
    "stylesheets" => array:4 [▼
      0 => "bundles/sonataadmin/app.css"
      1 => "bundles/sonataform/app.css"
      2 => "bundles/sonataadmin/admin-lte-skins/skin-black.min.css"
      3 => "bundles/shopsysadmin/css/admin.css"
    ]
    "role_admin" => "ROLE_SONATA_ADMIN"
    "role_super_admin" => "ROLE_SUPER_ADMIN"
    "search" => true
  ]
]

Code that causes this in my application is a parent() call in this block

{% block form_widget_simple %}
    {% set attr = attr|merge({'class': (attr.class|default('') ~ ' input')|trim}) %}
    {{ parent('form_widget_simple') }}
    {{- block('appendix_block') -}}
{% endblock form_widget_simple %}

If I remove Sonata from bundles.php the problem disappears.

I have not been able to pinpoint this any further, but I expect that the array should not be part of that widget.

github-actions[bot] commented 2 weeks ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.