Twig error when using a pattern in an admin theme and wrapping a rendered entity in a pattern

Created on 3 May 2023, over 1 year ago
Updated 17 November 2023, about 1 year ago

We noticed that with the recent UI Patterns version we are getting error 500 some times from the admin theme when creating content.

The error is following:

Twig\Error\LoaderError: Template "@templates/one-column/one_column.twig" is not defined in "modules/contrib/ui_patterns/templates/patterns-use-wrapper.html.twig" at line 9. funktiossa Twig\Loader\ChainLoader->getCacheKey() (rivi 98 tiedostossa /var/www/html/builds/2023-05-02.14-44-34.tag--2023-05-02__46e25145/vendor/twig/twig/src/Loader/ChainLoader.php).

There were a few related issues which were showing a similar error but not completely similar. The other similar errors seem to be related to UI Pattern Library and a child theme but in our case the error happens when we are using the admin theme and the pattern is defined in the main public theme.

Our use case is that in the admin panel we are also using the UI Patterns Field Formetter to display some fields with a pattern. We have selected the Rendered entity, wrapped in a pattern view mode for the field. Sometimes when you are adding multiple paragraphs in the page, there is an error 500 in the Network tab which gives the error message shown above.

I originally thought this might be a Paragraphs error because the bug was mostly happening when we were adding a paragraph with a pattern. There is a more complete description what happens when we are adding a new paragraph but today we noticed that the Ajax call is actually ending in a 500 error for the twig definition when the error seems to happen.

I was not 100% sure if this issue should go to this modules or https://www.drupal.org/project/issues/field_formatter_pattern issue queue but since the error is coming from the UI Patterns module I decided to report it here.

🐛 Bug report
Status

Needs work

Version

1.5

Component

Code

Created by

🇫🇮Finland heikkiy Oulu

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @heikkiy
  • 🇺🇸United States josh.fabean

    I'm having a similar issue, added ui_pattern display as a row display in a View, now I cannot edit my mega menu which uses a block from that view in it. I'm currently trying to figure if I can figure out a patch that checks to make sure template is available if not don't print or do something like Views does where it prints

    Pattern Views row plugin does not support preview.

  • 🇺🇸United States josh.fabean

    Here is a pretty crude patch that just checks if the current theme is admin theme and if so just won't render the pattern using the same method that Views uses inside the Views preview.

    I was thinking a better answer would be checking to confirm if template can be loaded, if it cannot output an error instead of white screening the website.

  • 🇫🇮Finland heikkiy Oulu

    @josh.fabean I can test the patch tomorrow but I suspect it might not solve our issue because we are not using Views when the issue happens but instead we are using a field formatter like in the picture.

  • Status changed to Needs review over 1 year ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    Patch Failed to Apply
  • 🇱🇺Luxembourg B-Prod

    here is a patch more global, which tries to fix this issue in a different way. Actually this issue is caused by the cache on run and could be easily fixed.
    When defining a pattern inside a front theme, and previewing on another theme (admin or other), you get this error.

    The patch also fixes compatibility with the ui_patterns_view integration.

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    80 pass, 2 fail
  • 🇱🇺Luxembourg B-Prod

    This is an update to the previous patch, for the current 1.x branch.

  • The last submitted patch, 7: ui_patterns-preview-pattern-from-other-theme-3357835-7.patch, failed testing. View results
    - codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

  • Status changed to Needs work about 1 year ago
  • 🇫🇮Finland heikkiy Oulu

    I tested the patch in #7 and I was still able to reproduce the issue. Then I found a similar issue from Components 🐛 Template is not defined error on admin pages when using administration theme Needs work . With both patches the error message still appears but it's more of a flash now before it disappears. I did get a screen capture of the error.

  • 🇸🇮Slovenia alesr

    I get this error:

    Twig\Error\LoaderError: There are no registered paths for namespace "components" in "modules/contrib/ui_patterns/templates/patterns-use-wrapper.html.twig" at line 9. in Twig\Loader\FilesystemLoader->findTemplate() (line 227 of /var/www/html/vendor/twig/twig/src/Loader/FilesystemLoader.php).
    

    where is just this line

    {% include use %}

    The patch in #7 didn't solve it for me.

Production build 0.71.5 2024