Sonataadminbundle: ModelAutocompleteType fails for entities without "create" route since 3.

Created on 7 Dec 2018  路  6Comments  路  Source: sonata-project/SonataAdminBundle

Environment

Sonata packages

$ composer show --latest 'sonata-project/*'
sonata-project/admin-bundle              3.42.2 3.42.2 The missing Symfony Admin Generator    
sonata-project/block-bundle              3.13.0 3.13.0 Symfony SonataBlockBundle
sonata-project/cache                     2.0.1  2.0.1  Cache library
sonata-project/core-bundle               3.12.0 3.12.0 Symfony SonataCoreBundle
sonata-project/datagrid-bundle           2.4.0  2.4.0  Symfony SonataDatagridBundle
sonata-project/doctrine-extensions       1.1.2  1.1.2  Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 3.6.3  3.6.3  Symfony Sonata / Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/exporter                  1.9.1  1.9.1  Lightweight Exporter library
sonata-project/intl-bundle               2.5.0  2.5.0  Symfony SonataIntlBundle

Symfony packages

$ composer show --latest 'symfony/*'
symfony/asset                v4.2.1  v4.2.1  Symfony Asset Component                          
symfony/browser-kit          v4.2.1  v4.2.1  Symfony BrowserKit Component
symfony/cache                v4.2.1  v4.2.1  Symfony Cache component with PSR-6, PSR-16, and tags
symfony/config               v4.2.1  v4.2.1  Symfony Config Component
symfony/console              v4.2.1  v4.2.1  Symfony Console Component
symfony/contracts            v1.0.2  v1.0.2  A set of abstractions extracted out of the Symfony components
symfony/css-selector         v4.2.1  v4.2.1  Symfony CssSelector Component
symfony/debug                v4.2.1  v4.2.1  Symfony Debug Component
symfony/dependency-injection v4.2.1  v4.2.1  Symfony DependencyInjection Component
symfony/doctrine-bridge      v4.2.1  v4.2.1  Symfony Doctrine Bridge
symfony/dom-crawler          v4.2.1  v4.2.1  Symfony DomCrawler Component
symfony/dotenv               v4.2.1  v4.2.1  Registers environment variables from a .env file
symfony/event-dispatcher     v4.2.1  v4.2.1  Symfony EventDispatcher Component
symfony/expression-language  v4.2.1  v4.2.1  Symfony ExpressionLanguage Component
symfony/filesystem           v4.2.1  v4.2.1  Symfony Filesystem Component
symfony/finder               v4.2.1  v4.2.1  Symfony Finder Component
symfony/flex                 v1.1.8  v1.1.8  Composer plugin for Symfony
symfony/form                 v4.2.1  v4.2.1  Symfony Form Component
symfony/framework-bundle     v4.2.1  v4.2.1  Symfony FrameworkBundle
symfony/http-foundation      v4.2.1  v4.2.1  Symfony HttpFoundation Component
symfony/http-kernel          v4.2.1  v4.2.1  Symfony HttpKernel Component
symfony/inflector            v4.2.1  v4.2.1  Symfony Inflector Component
symfony/intl                 v4.2.1  v4.2.1  A PHP replacement layer for the C intl extension that includes additional data from the ICU library.
symfony/monolog-bridge       v4.2.1  v4.2.1  Symfony Monolog Bridge
symfony/monolog-bundle       v3.3.1  v3.3.1  Symfony MonologBundle
symfony/options-resolver     v4.2.1  v4.2.1  Symfony OptionsResolver Component
symfony/phpunit-bridge       v4.2.1  v4.2.1  Symfony PHPUnit Bridge
symfony/polyfill-ctype       v1.10.0 v1.10.0 Symfony polyfill for ctype functions
symfony/process              v4.2.1  v4.2.1  Symfony Process Component
symfony/property-access      v4.2.1  v4.2.1  Symfony PropertyAccess Component
symfony/proxy-manager-bridge v4.2.1  v4.2.1  Symfony ProxyManager Bridge
symfony/routing              v4.2.1  v4.2.1  Symfony Routing Component
symfony/security             v4.2.1  v4.2.1  Symfony Security Component
symfony/security-acl         v3.0.1  v3.0.1  Symfony Security Component - ACL (Access Control List)
symfony/security-bundle      v4.2.1  v4.2.1  Symfony SecurityBundle
symfony/serializer           v4.2.1  v4.2.1  Symfony Serializer Component
symfony/stopwatch            v4.2.1  v4.2.1  Symfony Stopwatch Component
symfony/templating           v4.2.1  v4.2.1  Symfony Templating Component
symfony/translation          v4.2.1  v4.2.1  Symfony Translation Component
symfony/twig-bridge          v4.2.1  v4.2.1  Symfony Twig Bridge
symfony/twig-bundle          v4.2.1  v4.2.1  Symfony TwigBundle
symfony/validator            v4.2.1  v4.2.1  Symfony Validator Component
symfony/var-dumper           v4.2.1  v4.2.1  Symfony mechanism for exploring and dumping PHP variables
symfony/var-exporter         v4.2.1  v4.2.1  A blend of var_export() + serialize() to turn any serializable data structure to plain PHP code
symfony/web-profiler-bundle  v4.2.1  v4.2.1  Symfony WebProfilerBundle
symfony/yaml                 v4.2.1  v4.2.1  Symfony Yaml Component

PHP version

$ php -v
PHP 7.2.12 (cli) (built: Nov 16 2018 03:34:25) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Xdebug v2.6.1, Copyright (c) 2002-2018, by Derick Rethans

Subject

Using a ModelAutocompleteType on an entity which has an admin class with no create route throws an exception when rendering.

I believe this bug was introduced by caed9f37233638c1cf4a3bc7e1310c0546b1963e, as it tries to generate a route without checking if it exists.

Steps to reproduce

Create an admin with no create route. Create ModelAutocompleteType field referencing the model from the first admin.

Expected results

ModelAutocompleteType works.

Actual results

Twig_Error_Runtime:
An exception has been thrown during the rendering of a template ("Unable to generate a URL for the named route "admin_app_user_create" as such route does not exist.").

  at vendor/sonata-project/admin-bundle/src/Resources/views/Form/Type/sonata_type_model_autocomplete.html.twig:278
bug

Most helpful comment

Here I come, sorry for that, I will fix it ASAP

All 6 comments

ping @psyray no luck with this one :sweat_smile:

@sonata-project/contributors should we wait for @psyray or revert? Since this is the 3rd issue

Let鈥檚 wait for him, one can pin another version to fix it.
I would like to get this fixed by @psyray

Here I come, sorry for that, I will fix it ASAP

Fixed
I have to remove the required part because HTML 5 validation doesn't like hidden field which is required.
I think we should deeply check the Select2 component which seems to be broken in many part due to recent browser updates

Was this page helpful?
0 / 5 - 0 ratings