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

The service template_registry has a dependency on a non-existent service #5577

Closed VincentLanglet closed 5 years ago

VincentLanglet commented 5 years ago

Environment

Sonata packages

sonata-project/admin-bundle              3.40.3 3.49.0 The missing Symfony Admin Generator
sonata-project/block-bundle              3.15.0 3.15.0 Symfony SonataBlockBundle
sonata-project/cache                     2.0.1  2.0.1  Cache library
sonata-project/core-bundle               3.17.0 3.17.0 Symfony SonataCoreBundle
sonata-project/datagrid-bundle           2.5.0  2.5.0  Symfony SonataDatagridBundle
sonata-project/doctrine-extensions       1.3.0  1.3.0  Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 3.6.3  3.9.0  Symfony Sonata / Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/exporter                  1.11.1 1.11.1 Lightweight Exporter library

Symfony packages

symfony/monolog-bundle     v3.1.2  v3.3.1  Symfony MonologBundle
symfony/phpunit-bridge     v4.2.9  v4.3.0  Symfony PHPUnit Bridge
symfony/polyfill-apcu      v1.2.0  v1.11.0 Symfony polyfill backporting apcu_* functions to lower PHP versions
symfony/polyfill-ctype     v1.11.0 v1.11.0 Symfony polyfill for ctype functions
symfony/polyfill-iconv     v1.11.0 v1.11.0 Symfony polyfill for the Iconv extension
symfony/polyfill-intl-icu  v1.11.0 v1.11.0 Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-intl-idn  v1.11.0 v1.11.0 Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions
symfony/polyfill-mbstring  v1.11.0 v1.11.0 Symfony polyfill for the Mbstring extension
symfony/polyfill-php56     v1.11.0 v1.11.0 Symfony polyfill backporting some PHP 5.6+ features to lower PHP versions
symfony/polyfill-php70     v1.11.0 v1.11.0 Symfony polyfill backporting some PHP 7.0+ features to lower PHP versions
symfony/polyfill-php72     v1.11.0 v1.11.0 Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/polyfill-util      v1.11.0 v1.11.0 Symfony utilities for portability of PHP codes
symfony/security-acl       v3.0.2  v3.0.2  Symfony Security Component - ACL (Access Control List)
symfony/swiftmailer-bundle v3.2.6  v3.2.7  Symfony SwiftmailerBundle
symfony/symfony            v3.4.28 v4.3.0  The Symfony PHP framework

PHP version

PHP 7.2.17-1+0~20190412071344.20+stretch~1.gbp23a36d (cli) (built: Apr 12 2019 07:13:45) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.17-1+0~20190412071344.20+stretch~1.gbp23a36d, Copyright (c) 1999-2018, by Zend Technologies
    with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans

Subject

In the doc

There is an example of config

services:
     app.admin.post:
         class: App\Admin\PostAdmin
         arguments:
             - ~
             - App\Entity\Post
             - ~
         calls:
             - [setTemplate, ['edit', '@App/PostAdmin/edit.html.twig']]
         tags:
             - { name: sonata.admin, manager_type: orm, group: 'Content', label: 'Post' }

I get

The service app.admin.post.template_registry" has a dependency on a non-existent service "App/PostAdmin/edit.html.twig".

But both this solutions works

[setTemplate, ['edit', '@@App/PostAdmin/edit.html.twig']]
[setTemplate, ['edit', 'AppBundle:PostAdmin/edit.html.twig']]

Is there an issue with the doc ?

VincentLanglet commented 5 years ago

I found this

If you use a string that starts with @ or has % anywhere in it, you need to escape it by adding another @ or %:

the @ symbol does NOT need to be escaped in XML

greg0ire commented 5 years ago

I'm not sure but I think maybe the @ syntax has been deprecated in favor of the second syntax you used. Does anyone else remember something like this?

phansys commented 5 years ago

If I can remember correctly, @ notation is only for registered bundles. If you are trying to use your own templates, you must use a relative path from your templates directory (PostAdmin/edit.html.twig by instance).

phansys commented 5 years ago

See https://symfony.com/doc/current/best_practices/templates.html#template-locations.

phansys commented 5 years ago

You can also register your own namespaces if required: https://symfony.com/doc/current/templating/namespaced_paths.html#registering-your-own-namespaces.

VincentLanglet commented 5 years ago

Then I think, this doc (https://github.com/sonata-project/SonataAdminBundle/blob/master/docs/reference/templates.rst) should be updated.

Do you agree ?

phansys commented 5 years ago

Yes, I think that doc can be improved. Could you please create a PR?

phansys commented 5 years ago

@VincentLanglet, could you please share a reproducer for this issue? Thank you in advance.

VincentLanglet commented 5 years ago

@phansys I started a new project for a bug with createQuery and the searchAction. On this project I created a new branch to reproduce the bug of this issue https://github.com/VincentLanglet/sonataBug/pull/1/files

It was a Symfony 4 project, but to do as if it's a Symfony 3 project, I registered the templates folder.

You can see, adding

calls:
            - [setTemplate, ['list', '@App/list.html.twig']]

Break the app.

Adding

calls:
            - [setTemplate, ['list', '@@App/list.html.twig']]

Does not

haivala commented 3 years ago

This really should be documented at https://sonata-project.org/bundles/admin/master/doc/cookbook/recipe_row_templates.html#row-templates

VincentLanglet commented 3 years ago

Can you provide a PR @haivala ?

haivala commented 3 years ago

Dont have time :(