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

ListMapper::addIdentifier() does not generate link to edit pages #7832

Closed lobodol closed 2 years ago

lobodol commented 2 years ago

Environment

Sonata packages

show

``` $ composer show --latest 'sonata-project/*' ``` ``` sonata-project/admin-bundle 4.12.0 4.12.0 The missing Symfony Admin Generator sonata-project/block-bundle 4.12.0 4.12.0 Symfony SonataBlockBundle sonata-project/cache 2.2.0 2.2.0 Cache library Package sonata-project/cache is abandoned, you should avoid using it. No replacement was suggested. sonata-project/doctrine-extensions 1.17.0 1.17.0 Doctrine2 behavioral extensions sonata-project/doctrine-orm-admin-bundle 4.2.8 4.2.8 Integrate Doctrine ORM into the SonataAdminBundle sonata-project/exporter 2.11.0 2.11.0 Lightweight Exporter library sonata-project/form-extensions 1.16.0 1.16.0 Symfony form extensions sonata-project/twig-extensions 1.10.0 1.10.0 Sonata twig extensions ```

Symfony packages

show

``` $ composer show --latest 'symfony/*' ``` ``` symfony/apache-pack v1.0.1 = v1.0.1 A pack for Apache suppo... symfony/asset v4.4.40 ~ v5.4.7 Manages URL generation ... symfony/browser-kit v4.4.37 ~ v5.4.3 Simulates the behavior ... symfony/cache v4.4.41 ~ v5.4.8 Provides an extended PS... symfony/cache-contracts v2.5.1 = v2.5.1 Generic abstractions re... symfony/config v4.4.41 ~ v5.4.8 Helps you find, load, c... symfony/console v4.4.41 ~ v5.4.8 Eases the creation of b... symfony/css-selector v4.4.37 ~ v5.4.3 Converts CSS selectors ... symfony/debug v4.4.41 = v4.4.41 Provides tools to ease ... symfony/debug-bundle v4.4.37 ~ v5.4.3 Provides a tight integr... symfony/dependency-injection v4.4.41 ~ v5.4.8 Allows you to standardi... symfony/deprecation-contracts v2.5.1 = v2.5.1 A generic function and ... symfony/doctrine-bridge v4.4.41 ~ v5.4.8 Provides integration fo... symfony/dom-crawler v4.4.39 ~ v5.4.6 Eases DOM navigation fo... symfony/dotenv v4.4.37 ~ v5.4.5 Registers environment v... symfony/error-handler v4.4.41 ~ v5.4.8 Provides tools to manag... symfony/event-dispatcher v4.4.37 ~ v5.4.3 Provides tools that all... symfony/event-dispatcher-contracts v1.1.12 ~ v2.5.1 Generic abstractions re... symfony/expression-language v4.4.41 ~ v5.4.8 Provides an engine that... symfony/filesystem v4.4.39 ~ v5.4.7 Provides basic utilitie... symfony/finder v4.4.41 ~ v5.4.8 Finds files and directo... symfony/flex v1.18.7 = v1.18.7 Composer plugin for Sym... symfony/form v4.4.41 ~ v5.4.8 Allows to easily create... symfony/framework-bundle v4.4.41 ~ v5.4.8 Provides a tight integr... symfony/google-mailer v4.4.41 ~ v5.4.8 Symfony Google Mailer B... symfony/http-client v4.4.41 ~ v5.4.8 Provides powerful metho... symfony/http-client-contracts v2.5.1 = v2.5.1 Generic abstractions re... symfony/http-foundation v4.4.41 ~ v5.4.8 Defines an object-orien... symfony/http-kernel v4.4.41 ~ v5.4.8 Provides a structured p... symfony/inflector v4.4.37 ~ v5.4.3 Converts words between ... Package symfony/inflector is abandoned, you should avoid using it. Use EnglishInflector from the String component instead. symfony/intl v4.4.41 ~ v5.4.8 Provides a PHP replacem... symfony/mailer v4.4.41 ~ v5.4.8 Helps sending emails symfony/maker-bundle v1.39.0 ! v1.43.0 Symfony Maker helps you... symfony/mime v4.4.41 ~ v5.4.8 Allows manipulating MIM... symfony/monolog-bridge v4.4.37 ~ v5.4.3 Provides integration fo... symfony/monolog-bundle v3.8.0 = v3.8.0 Symfony MonologBundle symfony/options-resolver v4.4.37 ~ v5.4.3 Provides an improved re... symfony/phpunit-bridge v5.4.8 ~ v6.0.8 Provides utilities for ... symfony/polyfill-intl-grapheme v1.25.0 = v1.25.0 Symfony polyfill for in... symfony/polyfill-intl-icu v1.25.0 = v1.25.0 Symfony polyfill for in... symfony/polyfill-intl-idn v1.25.0 = v1.25.0 Symfony polyfill for in... symfony/polyfill-intl-normalizer v1.25.0 = v1.25.0 Symfony polyfill for in... symfony/polyfill-mbstring v1.25.0 = v1.25.0 Symfony polyfill for th... symfony/polyfill-php72 v1.25.0 = v1.25.0 Symfony polyfill backpo... symfony/polyfill-php73 v1.25.0 = v1.25.0 Symfony polyfill backpo... symfony/polyfill-php80 v1.25.0 = v1.25.0 Symfony polyfill backpo... symfony/polyfill-php81 v1.25.0 = v1.25.0 Symfony polyfill backpo... symfony/process v4.4.41 ~ v5.4.8 Executes commands in su... symfony/property-access v4.4.41 ~ v5.4.8 Provides functions to r... symfony/property-info v4.4.40 ~ v5.4.7 Extracts information ab... symfony/proxy-manager-bridge v4.4.39 ~ v5.4.6 Provides integration fo... symfony/routing v4.4.41 ~ v5.4.8 Maps an HTTP request to... symfony/security-acl v3.3.1 = v3.3.1 Symfony Security Compon... symfony/security-bundle v4.4.41 ~ v5.4.8 Provides a tight integr... symfony/security-core v4.4.41 ~ v5.4.8 Symfony Security Compon... symfony/security-csrf v4.4.37 ~ v5.4.3 Symfony Security Compon... symfony/security-guard v4.4.37 ~ v5.4.3 Symfony Security Compon... symfony/security-http v4.4.41 ~ v5.4.8 Symfony Security Compon... symfony/serializer v4.4.41 ~ v5.4.8 Handles serializing and... symfony/service-contracts v2.5.1 = v2.5.1 Generic abstractions re... symfony/stopwatch v4.4.38 ~ v5.4.5 Provides a way to profi... symfony/string v5.4.8 = v5.4.8 Provides an object-orie... symfony/templating v4.4.37 ~ v5.4.3 Provides all the tools ... symfony/translation v4.4.41 ~ v5.4.8 Provides tools to inter... symfony/translation-contracts v2.5.1 = v2.5.1 Generic abstractions re... symfony/twig-bridge v4.4.41 ~ v5.4.8 Provides integration fo... symfony/twig-bundle v4.4.41 ~ v5.4.8 Provides a tight integr... symfony/validator v4.4.41 ~ v5.4.8 Provides tools to valid... symfony/var-dumper v4.4.41 ~ v5.4.8 Provides mechanisms for... symfony/var-exporter v4.4.41 ~ v5.4.8 Allows exporting any se... symfony/web-link v4.4.37 ~ v5.4.3 Manages links between r... symfony/web-profiler-bundle v4.4.41 ~ v5.4.8 Provides a development ... symfony/webpack-encore-bundle v1.14.1 = v1.14.1 Integration with your S... symfony/yaml v4.4.37 ~ v5.4.3 Loads and dumps YAML files ```

PHP version

$ php -v
PHP 7.4.13 (cli) (built: Dec 11 2020 08:31:11) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.13, Copyright (c), by Zend Technologies
    with Xdebug v3.1.4, Copyright (c) 2002-2022, by Derick Rethans

Subject

I'm trying to upgrade SonataAdminBundle from ^3.39 to ^4.2. Until that, all worked as expected.

-        "sonata-project/admin-bundle": "^3.39",
-        "sonata-project/doctrine-orm-admin-bundle": "^3.6",
+        "sonata-project/admin-bundle": "^4.11",
+        "sonata-project/doctrine-orm-admin-bundle": "^4.2",

Hence, the method ListMapper::addIdentifier() does not have the behavior described in the documentation:

The fields which contain a link to the edit pages are called identifier fields. It makes sense to make the title field link to the edit page, so you can add it as an identifier field. This is done by using ListMapper#addIdentifier() instead of ListMapper#add():

Steps to reproduce

  1. Create an admin class
  2. Configure list fields implementing method configureListFields
  3. Use method ListMapper::addIdentifier() to add an identifier

Expected results

I expect the links of the list-view to be like /edit, as they always did.

Actual results

The links of the list-view are like /show.

<td class="sonata-ba-list-field sonata-ba-list-field-string" objectid="1">
    <a class="sonata-link-identifier" href="/admin/app/user/1/show"> user </a>
</td>
jordisala1991 commented 2 years ago

In Sonata 4 you can configure if the generated links are to show or edit. With a default to show.

lobodol commented 2 years ago

Hello,

Indeed, I noticed in the config reference that option.default_admin_route defaults to show.

IMO, it would be useful to update the documentation about ListMapper::addIdentifier(), because this method on its own does not generate an edit link. option.default_admin_route should also be set to edit.

What do you think about it?