Skip to content

Bundle root path detection issue #2610

@mpdude

Description

@mpdude

I have recently migrated a bundle from the "classic" to the "new" Symfony >= 4.4 bundle directory structure outlined here.

I noticed that at least two things do no longer work:

  • Templates from the template/ directory in the new location are not found
  • Following @BundleName/config/something.yml or similar imports in config files with a Cmd-Click does not work

For templates, there is #2335 describing that not only Resources/views should be indexed, but also the new templates directory. However, that directory is – in the recommended new layout – at ../templates relative to the BundleName.php bundle class file. And that brings me to the point where I think both issues are connected:

The BundleInterface::getPath method on the bundle class is used to indicate where the bundle "root" is. The TwigBundle will search templates at templates and Resources/views relative from there (see here). And config file imports with @BundleName/... should be based on that path as well.

My suspicion is that currently, the position of the bundle class .php file itself is taken as a reference point, which is not correct for the new directory layout.

My suggestion would be to use information from the kernel.bundles_metadata parameter in the dumped container XML file instead. It looks like this:

   ...
    <parameter key="kernel.bundles_metadata" type="collection">
      <parameter key="TwigBundle" type="collection">
        <parameter key="path">/fully/qualified/path/to/vendor/symfony/twig-bundle</parameter>
        <parameter key="namespace">Symfony\Bundle\TwigBundle</parameter>
      </parameter>
      <parameter key="MonologBundle" type="collection">
        <parameter key="path">/fully/qualified/path/to/vendor/symfony/monolog-bundle/src</parameter>
        <parameter key="namespace">Symfony\Bundle\MonologBundle</parameter>
      </parameter>

The path from this collection is what should be taken as the base for @BundleName/ imports, and relative to which templates and Resources/views (for Twig) should be considered.

Remember that in a development setup with Docker or a VM, path mappings may be in effect. So, it may be necessary to strip the value of kernel.project_dir from those paths to obtain a relative path that is valid in the host OS (where the IDE runs).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions