Blumlaut / EasyAdmin

Admin Menu for FiveM and RedM
https://easyadmin.readthedocs.io/
GNU Affero General Public License v3.0
169 stars 157 forks source link

[BUG] CollectionField entry ignores required fields #824

Closed Troi closed 8 months ago

Troi commented 8 months ago

Describe the bug

I have CollectionField with fields defined by useEntryCrudForm and different CrudController in which I have required text fields but I am getting exception from entity instead of UX/FE warning about empty text field.

To Reproduce

Steps to reproduce the behavior:

  1. define CollectionField and its inner fileds in FilmCrudController:
    CollectionField::new('translations', false)
            ->setEntryIsComplex()
            ->renderExpanded(false)
            ->allowAdd(false)
            ->allowDelete(false)
            ->showEntryLabel()
            ->useEntryCrudForm(FilmTranslationCrudController::class);

    in FilmTranslationCrudController:

    TextField::new('title', 'Title')
            ->setRequired(true);
  2. Create new Film, do not fill title
  3. Save
  4. See error Expected argument of type "string", "null" given at property path "title".

Expected behavior

I should see FE warning about empty field.

Stacktrace

Symfony\Component\PropertyAccess\Exception\InvalidArgumentException:
Expected argument of type "string", "null" given at property path "title".

  at vendor/symfony/property-access/PropertyAccessor.php:198
  at Symfony\Component\PropertyAccess\PropertyAccessor::throwInvalidArgumentException('App\\Film\\Entity\\FilmTranslation::setTitle(): Argument #1 ($title) must be of type string, null given, called in /var/www/html/vendor/symfony/property-access/PropertyAccessor.php on line 519', array(array('file' => '/var/www/html/vendor/symfony/property-access/PropertyAccessor.php', 'line' => 519, 'function' => 'setTitle', 'class' => 'App\\Film\\Entity\\FilmTranslation', 'type' => '->', 'args' => array(null)), array('file' => '/var/www/html/vendor/symfony/property-access/PropertyAccessor.php', 'line' => 120, 'function' => 'writeProperty', 'class' => 'Symfony\\Component\\PropertyAccess\\PropertyAccessor', 'type' => '->', 'args' => array(array(object(FilmTranslation)), 'title', null)), array('file' => '/var/www/html/vendor/symfony/form/Extension/Core/DataAccessor/PropertyPathAccessor.php', 'line' => 63, 'function' => 'setValue', 'class' => 'Symfony\\Component\\PropertyAccess\\PropertyAccessor', 'type' => '->', 'args' => array(object(FilmTranslation), object(PropertyPath), null)), array('file' => '/var/www/html/vendor/symfony/form/Extension/Core/DataAccessor/ChainAccessor.php', 'line' => 48, 'function' => 'setValue', 'class' => 'Symfony\\Component\\Form\\Extension\\Core\\DataAccessor\\PropertyPathAccessor', 'type' => '->', 'args' => array(object(FilmTranslation), null, object(Form))), array('file' => '/var/www/html/vendor/symfony/form/Extension/Core/DataMapper/DataMapper.php', 'line' => 73, 'function' => 'setValue', 'class' => 'Symfony\\Component\\Form\\Extension\\Core\\DataAccessor\\ChainAccessor', 'type' => '->', 'args' => array(object(FilmTranslation), null, object(Form))), array('file' => '/var/www/html/vendor/symfony/form/Form.php', 'line' => 552, 'function' => 'mapFormsToData', 'class' => 'Symfony\\Component\\Form\\Extension\\Core\\DataMapper\\DataMapper', 'type' => '->', 'args' => array(object(RecursiveIteratorIterator), object(FilmTranslation))), array('file' => '/var/www/html/vendor/symfony/form/Form.php', 'line' => 499, 'function' => 'submit', 'class' => 'Symfony\\Component\\Form\\Form', 'type' => '->', 'args' => array(array(), true)), array('file' => '/var/www/html/vendor/symfony/form/Form.php', 'line' => 499, 'function' => 'submit', 'class' => 'Symfony\\Component\\Form\\Form', 'type' => '->', 'args' => array(array('cs' => array('title' => '', 'slug' => '', 'subtitle' => '', 'synopsis' => '', 'description' => '', 'metadata' => array('title' => '', 'description' => '', 'ogImage' => array('file' => null))), 'en' => array('title' => '', 'slug' => '', 'subtitle' => '', 'synopsis' => '', 'description' => '', 'metadata' => array('title' => '', 'description' => '', 'ogImage' => array('file' => null)))), true)), array('file' => '/var/www/html/vendor/symfony/form/Extension/HttpFoundation/HttpFoundationRequestHandler.php', 'line' => 110, 'function' => 'submit', 'class' => 'Symfony\\Component\\Form\\Form', 'type' => '->', 'args' => array(array('translations' => array('cs' => array('title' => '', 'slug' => '', 'subtitle' => '', 'synopsis' => '', 'description' => '', 'metadata' => array('title' => '', 'description' => '', 'ogImage' => array('file' => null))), 'en' => array('title' => '', 'slug' => '', 'subtitle' => '', 'synopsis' => '', 'description' => '', 'metadata' => array('title' => '', 'description' => '', 'ogImage' => array('file' => null)))), 'showInCatalog' => '1', 'originalTitle' => 'sdfsdf', 'runtime' => '0', 'year' => '0', 'priceStream' => '', 'priceDownload' => '', 'priceStreamSubscriber' => '', 'priceDownloadSubscriber' => '', 'premiereAt' => '', 'monopolyEndsAt' => '', 'distributorTVODShare' => '', 'rating' => '', 'streamPermissionDuration' => '0', 'public_enabledFlag' => '1', 'public_enabledSince' => '', 'public_enabledUntil' => '', 'streamable_enabledFlag' => '1', 'streamable_enabledSince' => '', 'streamable_enabledUntil' => '', 'downloadable_enabledFlag' => '1', 'downloadable_enabledSince' => '', 'downloadable_enabledUntil' => '', 'svod_enabledFlag' => '1', 'svod_enabledSince' => '', 'svod_enabledUntil' => '', 'csfdUrl' => '', 'imdbUrl' => '', 'letterboxdUrl' => '', 'source' => array('cdn77Url' => '', 'audioLocale' => '', 'inVideoSubtitlesLocale' => ''), 'coverImagePath' => array('file' => object(UploadedFile)), 'previewImagePath' => array('file' => null)), true)), array('file' => '/var/www/html/vendor/symfony/form/Form.php', 'line' => 420, 'function' => 'handleRequest', 'class' => 'Symfony\\Component\\Form\\Extension\\HttpFoundation\\HttpFoundationRequestHandler', 'type' => '->', 'args' => array(object(Form), object(Request))), array('file' => '/var/www/html/vendor/easycorp/easyadmin-bundle/src/Controller/AbstractCrudController.php', 'line' => 304, 'function' => 'handleRequest', 'class' => 'Symfony\\Component\\Form\\Form', 'type' => '->', 'args' => array(object(Request))), array('file' => '/var/www/html/vendor/symfony/http-kernel/HttpKernel.php', 'line' => 181, 'function' => 'new', 'class' => 'EasyCorp\\Bundle\\EasyAdminBundle\\Controller\\AbstractCrudController', 'type' => '->', 'args' => array(object(AdminContext))), array('file' => '/var/www/html/vendor/symfony/http-kernel/HttpKernel.php', 'line' => 76, 'function' => 'handleRaw', 'class' => 'Symfony\\Component\\HttpKernel\\HttpKernel', 'type' => '->', 'args' => array(object(Request), 1)), array('file' => '/var/www/html/vendor/symfony/http-kernel/Kernel.php', 'line' => 197, 'function' => 'handle', 'class' => 'Symfony\\Component\\HttpKernel\\HttpKernel', 'type' => '->', 'args' => array(object(Request), 1, true)), array('file' => '/var/www/html/vendor/symfony/runtime/Runner/Symfony/HttpKernelRunner.php', 'line' => 35, 'function' => 'handle', 'class' => 'Symfony\\Component\\HttpKernel\\Kernel', 'type' => '->', 'args' => array(object(Request))), array('file' => '/var/www/html/vendor/autoload_runtime.php', 'line' => 29, 'function' => 'run', 'class' => 'Symfony\\Component\\Runtime\\Runner\\Symfony\\HttpKernelRunner', 'type' => '->', 'args' => array()), array('file' => '/var/www/html/public/index.php', 'line' => 5, 'args' => array('/var/www/html/vendor/autoload_runtime.php'), 'function' => 'require_once')), 0, 'title', object(TypeError))
     (vendor/symfony/property-access/PropertyAccessor.php:124)
  at Symfony\Component\PropertyAccess\PropertyAccessor->setValue(object(FilmTranslation), object(PropertyPath), null)
     (vendor/symfony/form/Extension/Core/DataAccessor/PropertyPathAccessor.php:63)
  at Symfony\Component\Form\Extension\Core\DataAccessor\PropertyPathAccessor->setValue(object(FilmTranslation), null, object(Form))
     (vendor/symfony/form/Extension/Core/DataAccessor/ChainAccessor.php:48)
  at Symfony\Component\Form\Extension\Core\DataAccessor\ChainAccessor->setValue(object(FilmTranslation), null, object(Form))
     (vendor/symfony/form/Extension/Core/DataMapper/DataMapper.php:73)
  at Symfony\Component\Form\Extension\Core\DataMapper\DataMapper->mapFormsToData(object(RecursiveIteratorIterator), object(FilmTranslation))
     (vendor/symfony/form/Form.php:552)
  at Symfony\Component\Form\Form->submit(array(), true)
     (vendor/symfony/form/Form.php:499)
  at Symfony\Component\Form\Form->submit(array('cs' => array('title' => '', 'slug' => '', 'subtitle' => '', 'synopsis' => '', 'description' => '', 'metadata' => array('title' => '', 'description' => '', 'ogImage' => array('file' => null))), 'en' => array('title' => '', 'slug' => '', 'subtitle' => '', 'synopsis' => '', 'description' => '', 'metadata' => array('title' => '', 'description' => '', 'ogImage' => array('file' => null)))), true)
     (vendor/symfony/form/Form.php:499)
  at Symfony\Component\Form\Form->submit(array('translations' => array('cs' => array('title' => '', 'slug' => '', 'subtitle' => '', 'synopsis' => '', 'description' => '', 'metadata' => array('title' => '', 'description' => '', 'ogImage' => array('file' => null))), 'en' => array('title' => '', 'slug' => '', 'subtitle' => '', 'synopsis' => '', 'description' => '', 'metadata' => array('title' => '', 'description' => '', 'ogImage' => array('file' => null)))), 'showInCatalog' => '1', 'originalTitle' => 'sdfsdf', 'runtime' => '0', 'year' => '0', 'priceStream' => '', 'priceDownload' => '', 'priceStreamSubscriber' => '', 'priceDownloadSubscriber' => '', 'premiereAt' => '', 'monopolyEndsAt' => '', 'distributorTVODShare' => '', 'rating' => '', 'streamPermissionDuration' => '0', 'public_enabledFlag' => '1', 'public_enabledSince' => '', 'public_enabledUntil' => '', 'streamable_enabledFlag' => '1', 'streamable_enabledSince' => '', 'streamable_enabledUntil' => '', 'downloadable_enabledFlag' => '1', 'downloadable_enabledSince' => '', 'downloadable_enabledUntil' => '', 'svod_enabledFlag' => '1', 'svod_enabledSince' => '', 'svod_enabledUntil' => '', 'csfdUrl' => '', 'imdbUrl' => '', 'letterboxdUrl' => '', 'source' => array('cdn77Url' => '', 'audioLocale' => '', 'inVideoSubtitlesLocale' => ''), 'coverImagePath' => array('file' => object(UploadedFile)), 'previewImagePath' => array('file' => null)), true)
     (vendor/symfony/form/Extension/HttpFoundation/HttpFoundationRequestHandler.php:110)
  at Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationRequestHandler->handleRequest(object(Form), object(Request))
     (vendor/symfony/form/Form.php:420)
  at Symfony\Component\Form\Form->handleRequest(object(Request))
     (vendor/easycorp/easyadmin-bundle/src/Controller/AbstractCrudController.php:304)
  at EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController->new(object(AdminContext))
     (vendor/symfony/http-kernel/HttpKernel.php:181)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
     (vendor/symfony/http-kernel/HttpKernel.php:76)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
     (vendor/symfony/http-kernel/Kernel.php:197)
  at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
     (vendor/symfony/runtime/Runner/Symfony/HttpKernelRunner.php:35)
  at Symfony\Component\Runtime\Runner\Symfony\HttpKernelRunner->run()
     (vendor/autoload_runtime.php:29)
  at require_once('/var/www/html/vendor/autoload_runtime.php')
     (public/index.php:5)                

Server Infos:

Blumlaut commented 8 months ago

the EasyAdmin you are looking for is in another castle: https://github.com/EasyCorp/EasyAdminBundle