Hello,

I have in my Drupal log warning like below. I don't think it's something wrong. In my scenario it's perfectly valid to have same names in different folders. This message could be useful during development for some, but it's definitely wrong in production environment. It's possible to make it optionable?

Found multiple files for the "@page/styleguide.twig" template; it is recommended to only have one "styleguide.twig" file in the "page" namespace’s "themes/custom/proficio/static/templates/page" directory

Source: https://git.drupalcode.org/project/components/-/blob/3.x/src/Template/Co...

Thank you

Issue fork components-3299045

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

parisek created an issue. See original summary.

immaculatexavier made their first commit to this issue’s fork.

immaculatexavier’s picture

Status: Active » Needs review
StatusFileSize
new706 bytes

As previously stated, I created a patch with one file in the "page" namespace.

Status: Needs review » Needs work

The last submitted patch, 3: 3299045-2.patch, failed testing. View results

parisek’s picture

Added MR and disabled logging warning "Found multiple files for the", seems it's not wide issue, patch is enough :)

parisek’s picture

codebymikey made their first commit to this issue’s fork.

codebymikey’s picture

Category: Feature request » Task
Status: Needs work » Needs review
Issue tags: +Needs tests
StatusFileSize
new1.31 KB
new3.04 KB
new3.03 KB

Attached a patch which allows sites to opt out of the warning using their settings.php file:

// Don't attempt to track duplicate templates.
$settings['components_ignore_duplicate_templates'] = TRUE;

Or on the theme/module level:

components:
  # Ignore duplicate templates.
  ignore_duplicate_templates: true

This still requires tests to be implemented, but works for my use case without breaking existing installations.
So feedback is more than welcome on the current implementation.

john cook’s picture

Status: Needs review » Reviewed & tested by the community

I had problems applying the diff / patch using cweagans/composer-patches, with a segment being rejected in components.info.yml. This was due to versioning information added by the packaging script on Drupal.org. I manually added the two line change before testing. I don't see this being a problem once the issue has been merged.

I tested with just the patch to make sure that the duplicates are reported by default. As expected, the errors appeared in the watchdog log.

Then I tried again after adding $settings['components_ignore_duplicate_templates'] = TRUE; to my settings.php. After I cleared the cache and refreshed the same page, the errors are no longer logged.

Moving to RTBC.

john cook’s picture

As a side note, I noticed this bug because I have /web as a symlink to /docroot after changing host providers.

acbramley’s picture

Status: Reviewed & tested by the community » Needs work

Still NW on tests

dpi’s picture

To me, it seems the log simply didn't receive a lot of scrutiny (none) when added in #3191392: Make subdirectory path optional when using @namespace/template syntax.

Perhaps instead, we should just remove the log.

All this configuration seems a bit much.

johnalbin’s picture

Perhaps instead, we should just remove the log.

Agreed.

But we should also prevent any duplicated twig file name from being referenced using the short form, e.g. @page/styleguide.twig won't work but @page/full-path-to-file/styleguide.twig would. Nevermind, that would be a breaking change.

johnalbin changed the visibility of the branch 3299045-prevent-short-paths-of-dupes to hidden.

johnalbin changed the visibility of the branch 3299045-duplicate-templates-in to hidden.

johnalbin’s picture

Title: Duplicate templates in same namespace is valid use case » Prevent logging of duplicate template filenames
Status: Needs work » Needs review

  • johnalbin committed 057d1c83 on 3.x
    bug: #3299045 Prevent logging of duplicate template filenames
    
    By:...
johnalbin’s picture

Category: Task » Bug report
Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.