sonata-project / SonataAdminBundle

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

navbar_title missing for list view #8169

Open bobemoe opened 3 months ago

bobemoe commented 3 months ago

The navbar_title on list view pages is blank which makes it a harder to know where you are. We have many admin entities and it would be helpful to use this space with a sensible heading. I know the breadcrumbs show where you are but the absence of this seems inconsistent and trying to trace the code through, looks like we are expecting something to be displayed there.

Environment

Latest Symfony/Sonata on linux nginx docker.

Sonata packages

show

``` $ composer show --latest 'sonata-project/*' sonata-project/admin-bundle 4.29.3 4.29.3 The missing Symfony Admin Generator 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.3.0 2.3.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/asset v7.0.3 v7.0.3 Manages URL generation and versioning of web assets such as CSS stylesheets, Ja... symfony/asset-mapper v7.0.5 v7.0.5 Maps directories of assets & makes them available in a public directory with ve... symfony/browser-kit v7.0.3 v7.0.3 Simulates the behavior of a web browser, allowing you to make requests, click o... symfony/console v7.0.4 v7.0.4 Eases the creation of beautiful and testable command line interfaces symfony/css-selector v7.0.3 v7.0.3 Converts CSS selectors to XPath expressions symfony/debug-bundle v7.0.3 v7.0.3 Provides a tight integration of the Symfony VarDumper component and the ServerL... symfony/doctrine-messenger v7.0.4 v7.0.4 Symfony Doctrine Messenger Bridge symfony/dotenv v7.0.4 v7.0.4 Registers environment variables from a .env file symfony/expression-language v7.0.3 v7.0.3 Provides an engine that can compile and evaluate expressions symfony/flex v2.4.5 v2.4.5 Composer plugin for Symfony symfony/form v7.0.4 v7.0.4 Allows to easily create, process and reuse HTML forms symfony/framework-bundle v7.0.4 v7.0.4 Provides a tight integration between Symfony components and the Symfony full-st... symfony/http-client v7.0.5 v7.0.5 Provides powerful methods to fetch HTTP resources synchronously or asynchronously symfony/intl v7.0.3 v7.0.3 Provides access to the localization data of the ICU library symfony/mailer v7.0.4 v7.0.4 Helps sending emails symfony/maker-bundle v1.57.0 v1.57.0 Symfony Maker helps you create empty commands, controllers, form classes, tests... symfony/mime v7.0.3 v7.0.3 Allows manipulating MIME messages symfony/monolog-bundle v3.10.0 v3.10.0 Symfony MonologBundle symfony/notifier v7.0.3 v7.0.3 Sends notifications via one or more channels (email, SMS, ...) symfony/phpunit-bridge v7.0.4 v7.0.4 Provides utilities for PHPUnit, especially user deprecation notices management symfony/process v7.0.4 v7.0.4 Executes commands in sub-processes symfony/property-access v7.0.4 v7.0.4 Provides functions to read and write from/to an object or array using a simple ... symfony/property-info v7.0.3 v7.0.3 Extracts information about PHP class' properties using metadata of popular sources symfony/runtime v7.0.3 v7.0.3 Enables decoupling PHP applications from global state symfony/security-bundle v7.0.5 v7.0.5 Provides a tight integration of the Security component into the Symfony full-st... symfony/serializer v7.0.4 v7.0.4 Handles serializing and deserializing data structures, including object graphs,... symfony/stimulus-bundle v2.16.0 v2.16.0 Integration with your Symfony app & Stimulus! symfony/stopwatch v7.0.3 v7.0.3 Provides a way to profile code symfony/string v7.0.4 v7.0.4 Provides an object-oriented API to strings and deals with bytes, UTF-8 code poi... symfony/translation v7.0.4 v7.0.4 Provides tools to internationalize your application symfony/twig-bundle v7.0.4 v7.0.4 Provides a tight integration of Twig into the Symfony full-stack framework symfony/ux-turbo v2.16.0 v2.16.0 Hotwire Turbo integration for Symfony symfony/validator v7.0.5 v7.0.5 Provides tools to validate values symfony/web-link v7.0.3 v7.0.3 Manages links between resources symfony/web-profiler-bundle v7.0.4 v7.0.4 Provides a development tool that gives detailed information about the execution... symfony/yaml v7.0.3 v7.0.3 Loads and dumps YAML files Transitive dependencies not required in composer.json: symfony/cache v7.0.4 v7.0.4 Provides extended PSR-6, PSR-16 (and tags) implementations symfony/cache-contracts v3.4.0 v3.4.0 Generic abstractions related to caching symfony/clock v7.0.5 v7.0.5 Decouples applications from the system clock symfony/config v7.0.4 v7.0.4 Helps you find, load, combine, autofill and validate configuration values of an... symfony/dependency-injection v7.0.4 v7.0.4 Allows you to standardize and centralize the way objects are constructed in you... symfony/deprecation-contracts v3.4.0 v3.4.0 A generic function and convention to trigger deprecation notices symfony/doctrine-bridge v7.0.5 v7.0.5 Provides integration for Doctrine with various Symfony components symfony/dom-crawler v7.0.4 v7.0.4 Eases DOM navigation for HTML and XML documents symfony/error-handler v7.0.4 v7.0.4 Provides tools to manage errors and ease debugging PHP code symfony/event-dispatcher v7.0.3 v7.0.3 Provides tools that allow your application components to communicate with each ... symfony/event-dispatcher-contracts v3.4.0 v3.4.0 Generic abstractions related to dispatching event symfony/filesystem v7.0.3 v7.0.3 Provides basic utilities for the filesystem symfony/finder v7.0.0 v7.0.0 Finds files and directories via an intuitive fluent interface symfony/http-client-contracts v3.4.0 v3.4.0 Generic abstractions related to HTTP clients symfony/http-foundation v7.0.4 v7.0.4 Defines an object-oriented layer for the HTTP specification symfony/http-kernel v7.0.5 v7.0.5 Provides a structured process for converting a Request into a Response symfony/messenger v7.0.4 v7.0.4 Helps applications send and receive messages to/from other applications or via ... symfony/monolog-bridge v7.0.3 v7.0.3 Provides integration for Monolog with various Symfony components symfony/options-resolver v7.0.0 v7.0.0 Provides an improved replacement for the array_replace PHP function symfony/password-hasher v7.0.4 v7.0.4 Provides password hashing utilities symfony/polyfill-intl-grapheme v1.29.0 v1.29.0 Symfony polyfill for intl's grapheme_* functions symfony/polyfill-intl-icu v1.29.0 v1.29.0 Symfony polyfill for intl's ICU-related data and classes symfony/polyfill-intl-idn v1.29.0 v1.29.0 Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions symfony/polyfill-intl-normalizer v1.29.0 v1.29.0 Symfony polyfill for intl's Normalizer class and related functions symfony/polyfill-mbstring v1.29.0 v1.29.0 Symfony polyfill for the Mbstring extension symfony/polyfill-php83 v1.29.0 v1.29.0 Symfony polyfill backporting some PHP 8.3+ features to lower PHP versions symfony/routing v7.0.5 v7.0.5 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-core v7.0.3 v7.0.3 Symfony Security Component - Core Library symfony/security-csrf v7.0.3 v7.0.3 Symfony Security Component - CSRF Library symfony/security-http v7.0.4 v7.0.4 Symfony Security Component - HTTP Integration symfony/service-contracts v3.4.1 v3.4.1 Generic abstractions related to writing services symfony/translation-contracts v3.4.1 v3.4.1 Generic abstractions related to translation symfony/twig-bridge v7.0.4 v7.0.4 Provides integration for Twig with various Symfony components symfony/var-dumper v7.0.4 v7.0.4 Provides mechanisms for walking through any arbitrary PHP variable symfony/var-exporter v7.0.4 v7.0.4 Allows exporting any serializable PHP data structure to plain PHP code ```

PHP version

$ php -v
PHP 8.2.7 (cli) (built: Jun  9 2023 19:37:27) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.7, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.7, Copyright (c), by Zend Technologies

Subject

Steps to reproduce

composer create-project symfony/skeleton:"7.0.*" sonata_test
cd sonata_test/
composer require webapp
composer require sonata-project/doctrine-orm-admin-bundle
nano .env # setup a simple test db, i just uncommented the default sqlite line
bin/console make:entity #  make a simple test entity, I just made "Test" with no other fields
bin/console make:sonata:admin # make admin for the above entity
bin/console do:sc:up --force
symfony server:start

browse to /admin/app/test/list and see there is no navbar_title: Screenshot_2024-03-25_13-53-44

Other pages such as edit or show have an appropriate navbar_title:

Screenshot_2024-03-25_13-54-05

Expected results

Nav title should not be blank, there is a appropriate title in breadcrubms and html title, not sure why it is missing from navbar_title?

Actual results

{% block title %}
    {{ admin.isChild and admin.parent.subject ? 'title_edit'|trans({'%name%': admin.parent.toString(admin.parent.subject)|u.truncate(15, '...') }, 'SonataAdminBundle') : '' }}
{% endblock %}

{% block navbar_title %}
    {{ admin.isChild and admin.parent.subject ? 'title_edit'|trans({'%name%': admin.parent.toString(admin.parent.subject)|u.truncate(100, '...') }, 'SonataAdminBundle') : '' }}
{% endblock %}

Seems this is the code responsible for the title and navbar_title, admin.isChild is false so not executed leaving it blank. Not sure how Title has the appropriate text and navbar_title ends up blank :/

Fix / Workaround

I have overridden the @SonataAdmin/CRUD/list.html.twig template with:

{% extends '@SonataAdmin/CRUD/base_list.html.twig' %}
{% block navbar_title %}
{{ admin.label }} List
{% endblock %}

And now my nav title works as expected.

Screenshot_2024-03-25_14-24-01

Obviously not a real fix as no translations and removed the possibly needed isChild test etc.

VincentLanglet commented 3 months ago

Hi ! Do you want to provide a PR ?

bobemoe commented 3 months ago

Could do, its not very nice code, pretty sure I've stripped out necessary things :/ Probably better of someone familiar with the codebase having a go?

VincentLanglet commented 3 months ago

Could do, its not very nice code, pretty sure I've stripped out necessary things :/

Sure, a PR with

You can change

{{ admin.isChild and admin.parent.subject ? 'title_edit'|trans({'%name%': admin.parent.toString(admin.parent.subject)|u.truncate(15, '...') }, 'SonataAdminBundle') :  (admin.label ~ ' List') }}

won't be accepted. It should at least use a translation key.

You could try to display the same than the one in the breadcrumb

image

It should be something like

{{
  admin.isChild and admin.parent.subject 
    ? 'title_edit'|trans({'%name%': admin.parent.toString(admin.parent.subject)|u.truncate(15, '...') }, 'SonataAdminBundle')
    : (admin.classnameLabel ~ '_list')|trans({},  admin.translationDomain)
}}

Probably better of someone familiar with the codebase having a go?

There is generally none. All contributors/maintainers are doing it on their free time, so they generally prefer to work on their own issue.