Twig\Error\RuntimeError: The callable passed to the "filter" filter must be a Closure in sandbox mode.

Created on 22 August 2022, almost 2 years ago
Updated 27 April 2024, 2 months ago

Problem/Motivation

When creating a new tabs section in layout builder, the site throws a 500 error and the section is not created.
Error log reports: Twig\Error\RuntimeError: The callable passed to the "filter" filter must be a Closure in sandbox mode.
After that error, the layout builder edition of that node throws a "The website encountered an unexpected error. Please try again later." Drupal error.

Steps to reproduce

  • Fresh Drupal 9 installation with enabled Layout Builder and Layout Builder Tabs Section
  • Create content type "Component page" and Enable Layout builder for it, along with the "Allow each content item to have its layout customized" checkbox.
  • Create a node of the mentioned content type.
  • Edit it via Layout builder and try to add a new Tabs section.
πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡ͺπŸ‡ΈSpain joe_carvajal Seville (Spain)

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

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Installed this module today and immediately ran into this bug (D9.5.4, PHP8.1). Thank you for patch #3! Great module, very easy to use.

  • Status changed to Needs work over 1 year ago
  • πŸ‡¨πŸ‡¦Canada mandclu

    The change in question was introduced for the sake of Drupal 10 compatibility, specifically the newer version of Twig used. With the patch applied, Upgrade Status once again highlights three problems for this module:

    Using an "if" condition on "for" tag in "modules/custom/layout_builder_tabs/templates/tabs.html.twig" at line 18 is deprecated since Twig 2.10.0, use a "filter" filter or an "if" condition inside the "for" body instead (if your condition depends on a variable updated inside the loop). See https://drupal.org/node/3071078.

    It's definitely regrettable that the changes have created an issue for Drupal 9.x sites, but we need to find a solution that doesn't break Drupal 10 compatibility. I'll experiment with the solution originally suggest in #3308336: Twig\Error\RuntimeError: The callable passed to the "filter" filter must be a Closure in sandbox mode β†’ which is slightly different, to see if that might fix the issue while maintaining compatibility with the most recent versions of Drupal.

  • Status changed to Needs review over 1 year ago
  • πŸ‡¨πŸ‡¦Canada mandclu

    Here's an updated patch that should avoid Twig errors in Drupal 9 and 10.

  • Using the patch above, when you add an empty Tab section, this is what you get
    Twig\Error\RuntimeError: The "filter" filter expects an array or "Traversable", got "NULL". in twig_array_filter() (line 18 of modules/contrib/layout_builder_tabs/templates/tabs.html.twig).

    But for tab section with content, it works well.

  • πŸ‡ΊπŸ‡ΈUnited States GuyManDude

    The #11 patch is not working for my D10 site. It has also rendered Layout Builder for that content type even after uninstalling both Layout Builder and Layout Builder Tabs and reinstalling Layout Builder.

    Prior to patch, got this error when clicking Manage Layout:

    Warning: Undefined array key "block_id" in __TwigTemplate_4a3fe46f3c0ba04dfda5c592bf4b89f1->doDisplay() (line 173 of sites/default/files/php/twig/6460750b6f7e8_tabs.html.twig_5sroUazadlcoTpU0Pqk4ZMapg/hfLTqiiT0Z2P2C3pwfsvkun2lluC9YVZyTgo32fTQp8.php).

    After patch, got this error when clicking Manage Layout:

    The website encountered an unexpected error. Please try again later.

    Twig\Error\RuntimeError: The callable passed to the "filter" filter must be a Closure in sandbox mode. in twig_check_arrow_in_sandbox() (line 41 of modules/layout_builder_tabs/templates/tabs.html.twig).

  • Patch #11 works fine for me on a clean 10.1.3 site. The cache needs to be cleared though before the error disappears. I'm also getting the error mentioned in #13 if I add an empty tab section, so one should add blocks to it straight away before saving the layout. I suppose an extra check is needed to test wether any blocks are present.

  • πŸ‡ͺπŸ‡ΈSpain pgrandeg

    I agree with @GuyManDude this patch solves the problem only partially.
    The #11 patch works good while creating nodes, but it is crashing when you use an empty (no blocks inside) 'Tabs' region in a view mode configuration with Layout Builder.

    Steps to recreate:
    Create a CT
    Go to Manage display use default or enable 'full'
    Enable to use Layout Builder and to use LB in nodes
    Configure 'default' or 'full' layout
    Include a new 'Tabs' section to the layout with no content, no blocks inside
    Create a new node of that CT, then you will see the error Twig\Error\RuntimeError: The callable passed to the "filter" filter must be a Closure in sandbox mode. in twig_check_arrow_in_sandbox() (line 41 of modules/layout_builder_tabs/templates/tabs.html.twig).

    I have prepared a patch to set the 'tabs' $build index when it is not setted, and it works perfect in my environment.

    I hope it helps

  • πŸ‡ͺπŸ‡ΈSpain joe_carvajal Seville (Spain)

    #17 seems to be working fine in D10. Thank you!

  • πŸ‡―πŸ‡²Jamaica axle_foley00

    I had this issue as well and the patch in #17 worked for me.

  • πŸ‡¦πŸ‡ΉAustria drupalfan2

    Patch #17 worked after Drupal 10 Upgrade.

  • Status changed to RTBC 4 months ago
  • Status changed to Fixed 2 months ago
  • πŸ‡¨πŸ‡¦Canada mandclu

    Thanks for everyone's work on this issue. This fix has been committed, and will be included in a new, D11-ready release soon.

    • mandclu β†’ committed f228b48b on 1.0.x
      Issue #3305095 by pgrandeg, joe_carvajal, mandclu: Twig\Error\...
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024