Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Form validation errors for a block do not display for the CollectionType #1770

Open
Daric971 opened this issue Aug 26, 2024 · 0 comments · May be fixed by #1781
Open

Form validation errors for a block do not display for the CollectionType #1770

Daric971 opened this issue Aug 26, 2024 · 0 comments · May be fixed by #1781

Comments

@Daric971
Copy link
Contributor

Environment

Sonata packages

show

$ composer show --latest 'sonata-project/*'
sonata-project/admin-bundle              4.29.3 4.31.0 The missing Symfony Admin Generator
sonata-project/doctrine-orm-admin-bundle 4.15.0 4.17.1 Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/media-bundle              4.11.0 4.13.0 Symfony SonataMediaBundle
sonata-project/page-bundle               4.7.1  4.7.2  This bundle provides a Site and Page management through container and block services
sonata-project/block-bundle              5.1.0  5.1.0  Symfony SonataBlockBundle
sonata-project/doctrine-extensions       2.3.0  2.4.1  Doctrine2 behavioral extensions
sonata-project/exporter                  3.3.0  3.3.0  Lightweight Exporter library
sonata-project/form-extensions           2.3.0  2.4.0  Symfony form extensions
sonata-project/seo-bundle                3.8.0  3.8.0  Symfony SonataSeoBundle
sonata-project/twig-extensions           2.4.0  2.4.0  Sonata twig extensions

Symfony packages

show

$ composer show --latest 'symfony/*'
symfony/asset                      v6.4.3  v7.1.1  Manages URL generation and versioning of web assets such as CSS stylesheets, JavaScript files and image files
symfony/cache                      v6.4.3  v7.1.3  Provides extended PSR-6, PSR-16 (and tags) implementations
symfony/cache-contracts            v3.4.0  v3.5.0  Generic abstractions related to caching
symfony/clock                      v6.4.3  v7.1.1  Decouples applications from the system clock
symfony/config                     v6.4.3  v7.1.1  Helps you find, load, combine, autofill and validate configuration values of any kind
symfony/dependency-injection       v6.4.3  v7.1.3  Allows you to standardize and centralize the way objects are constructed in your application
symfony/deprecation-contracts      v3.4.0  v3.5.0  A generic function and convention to trigger deprecation notices
symfony/doctrine-bridge            v6.4.3  v7.1.3  Provides integration for Doctrine with various Symfony components
symfony/error-handler              v6.4.3  v7.1.3  Provides tools to manage errors and ease debugging PHP code
symfony/event-dispatcher           v6.4.3  v7.1.1  Provides tools that allow your application components to communicate with each other by dispatching events and listening to them
symfony/event-dispatcher-contracts v3.4.0  v3.5.0  Generic abstractions related to dispatching event
symfony/expression-language        v6.4.3  v7.1.1  Provides an engine that can compile and evaluate expressions
symfony/filesystem                 v6.4.3  v7.1.2  Provides basic utilities for the filesystem
symfony/finder                     v6.4.0  v7.1.3  Finds files and directories via an intuitive fluent interface
symfony/form                       v6.4.3  v7.1.3  Allows to easily create, process and reuse HTML forms
symfony/http-client                v6.4.3  v7.1.3  Provides powerful methods to fetch HTTP resources synchronously or asynchronously
symfony/http-client-contracts      v3.4.0  v3.5.0  Generic abstractions related to HTTP clients
symfony/http-foundation            v6.4.3  v7.1.3  Defines an object-oriented layer for the HTTP specification
symfony/http-kernel                v6.4.3  v7.1.3  Provides a structured process for converting a Request into a Response
symfony/intl                       v6.4.3  v7.1.1  Provides access to the localization data of the ICU library
symfony/mime                       v6.4.3  v7.1.2  Allows manipulating MIME messages
symfony/options-resolver           v6.4.0  v7.1.1  Provides an improved replacement for the array_replace PHP function
symfony/password-hasher            v6.4.3  v7.1.1  Provides password hashing utilities
symfony/polyfill-intl-grapheme     v1.28.0 v1.30.0 Symfony polyfill for intl's grapheme_* functions
symfony/polyfill-intl-icu          v1.28.0 v1.30.0 Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-intl-idn          v1.28.0 v1.30.0 Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions
symfony/polyfill-intl-normalizer   v1.28.0 v1.30.0 Symfony polyfill for intl's Normalizer class and related functions
symfony/polyfill-mbstring          v1.28.0 v1.30.0 Symfony polyfill for the Mbstring extension
symfony/polyfill-php83             v1.28.0 v1.30.0 Symfony polyfill backporting some PHP 8.3+ features to lower PHP versions
symfony/process                    v6.4.3  v7.1.3  Executes commands in sub-processes
symfony/property-access            v6.4.3  v7.1.1  Provides functions to read and write from/to an object or array using a simple string notation
symfony/property-info              v6.4.3  v7.1.3  Extracts information about PHP class' properties using metadata of popular sources
symfony/routing                    v6.4.3  v7.1.3  Maps an HTTP request to a set of configuration variables
symfony/security-acl               v3.3.3  v3.3.3  Symfony Security Component - ACL (Access Control List)
symfony/security-bundle            v6.4.3  v7.1.3  Provides a tight integration of the Security component into the Symfony full-stack framework
symfony/security-core              v6.4.3  v7.1.3  Symfony Security Component - Core Library
symfony/security-csrf              v6.4.3  v7.1.1  Symfony Security Component - CSRF Library
symfony/security-http              v6.4.3  v7.1.3  Symfony Security Component - HTTP Integration
symfony/serializer                 v6.4.3  v7.1.3  Handles serializing and deserializing data structures, including object graphs, into array structures or other formats like XML and JSON.
symfony/service-contracts          v3.4.1  v3.5.0  Generic abstractions related to writing services
symfony/string                     v6.4.3  v7.1.3  Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a unified way
symfony/translation                v6.4.3  v7.1.3  Provides tools to internationalize your application
symfony/translation-contracts      v3.4.1  v3.5.0  Generic abstractions related to translation
symfony/twig-bridge                v6.4.3  v7.1.1  Provides integration for Twig with various Symfony components
symfony/twig-bundle                v6.4.3  v7.1.1  Provides a tight integration of Twig into the Symfony full-stack framework
symfony/validator                  v6.4.3  v7.1.3  Provides tools to validate values
symfony/var-dumper                 v6.4.3  v7.1.3  Provides mechanisms for walking through any arbitrary PHP variable
symfony/var-exporter               v6.4.3  v7.1.2  Allows exporting any serializable PHP data structure to plain PHP code

PHP version

$ php -v
PHP 8.3.9 (cli) (built: Jul  6 2024 01:15:14) (ZTS)
Copyright (c) The PHP Group
Zend Engine v4.3.9, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.9, Copyright (c), by Zend Technologies
    with Xdebug v3.3.2, Copyright (c) 2002-2024, by Derick Rethans

Subject

In the context of my project, I need to add a collection of fields to the 'settings' of a block. The collection must contain at least three items for the form to be valid.
When I go to page-compose to create (or edit) the block and do not meet the given constraint, I notice an error appearing in the debug console, but the error messages are not displayed in the back office (no flash message, the input does not have the 'error' class). However, I observe the expected behavior when I create a shared block.

Minimal repository with the bug

After investigation, this is due to the modification of composer.js when upgrading to version 4.*

Steps to reproduce

I configure my form

public function configureEditForm(FormMapper $form, BlockInterface $block): void
    {
        $form->add('settings', ImmutableArrayType::class, [
            'keys' => [
                ['content', TextareaType::class, [
                    'label' => 'form.title',
                    'translation_domain' => 'SonataBlockBundle',
                ]],
                [
                    'covers',
                    CollectionType::class,
                    [
                        'label' => 'list of cover',
                        'required' => true,
                        'entry_type' => ImmutableArrayType::class,
                        'entry_options' => [
                            'label' => false,
                            'keys' => [
                                [
                                    'label',
                                    TextareaType::class,
                                    [
                                        'label' => 'form.label',
                                        'translation_domain' => 'SonataBlockBundle',
                                        'required' => true,
                                    ],
                                ],
                                [
                                    'description',
                                    TextareaType::class,
                                    [
                                        'label' => 'form.description',
                                        'translation_domain' => 'SonataBlockBundle',
                                        'required' => true,
                                    ],
                                ],
                            ],
                        ],
                        'allow_add' => true,
                        'allow_delete' => true,
                        'delete_empty' => true,
                    ],
                ],
            ],
            'translation_domain' => 'SonataBlockBundle',
        ]);
    }

I add validation rules

public function validate(ErrorElement $errorElement, BlockInterface $block): void
    {
        $errorElement
            ->with('settings[covers]')
                ->addConstraint(new Count(['min' => 3]))
            ->end();
    }

Expected results

Constraint error

Actual results

Error in debug Bar
image

Screen record

issue.page.bundle.mov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants
@Daric971 and others