Fix component view exception must be of type array, false given

Created on 14 January 2025, 3 months ago

Problem/Motivation

The website encountered an unexpected error. Try again later.

Twig\Error\RuntimeError: An exception has been thrown during the rendering of a template ("Twig\Template::yield(): Argument #1 ($context) must be of type array, false given, called in /var/www/html/web/sites/default/files/php/twig/6786687c05b55___string_template__82e8cd_gpBNLZWW7jOQhVB-Z59cLPL5X/MxtXYrawophiXVENdS_Aghnnr9ca-SP9SCh8U_Brfak.php on line 80") in "__string_template__82e8cd06e2834b072b15db53ddd0917d" at line 18. in Twig\Template->yield() (line 407 of /var/www/html/vendor/twig/twig/src/Template.php).
__TwigTemplate_09f4b18b9fba1894faa0b531c5073984->doDisplay() (Line: 393)
Twig\Template->yield() (Line: 349)

Steps to reproduce

  1. On a fresh Drupal 10.3.11 instance, install the DAB module.
  2. Visit the Drupal Atomic Builder component list page.
  3. Click the Teaser component from Olivero.

You'll see the error.

This error also appears in testing with UI Suite USWDS components.

Proposed resolution

I've confirmed the error that the $context['data'] comes back false in vendor/twig/twig/src/Template.php.

πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States jcandan

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

Comments & Activities

  • Issue created by @jcandan
  • πŸ‡ΊπŸ‡ΈUnited States jcandan
  • πŸ‡ΊπŸ‡ΈUnited States jcandan
  • πŸ‡ΊπŸ‡ΈUnited States jcandan
  • πŸ‡ΊπŸ‡ΈUnited States jcandan

    What is the purpose of $version here?

  • πŸ‡«πŸ‡·France Quentin Harelle

    In this context $version is an array with the props recovered from the component.yml file.

    I'm investigating this bug, I'll get back to you.

  • πŸ‡«πŸ‡·France Quentin Harelle

    I made a patch that seems to fix this issue.

    The issue was that some component.yml files might not have examples, which I use in $this->versions and $currentVersion. In that case I just needed to send an empty array to display the component without adding examples values in it.

    Can you tell me if it's okay for you ?

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

    Reviewed.

    This did fix the Olivero Teaser. Obviously, nothing is shown, but there's no error.

    I did try with UI Suite USWDS, and although the components provided by that theme also were blank, no errors were shown.

    However, once that theme was enabled, I did get the following error in the Olivero Teaser component view:

    The website encountered an unexpected error. Try again later.
    
    Twig\Error\RuntimeError: An exception has been thrown during the rendering of a template ("Data provided to prop "attributes" for component "olivero:teaser" is not a valid instance of "Drupal\Core\Template\Attribute""). in Twig\Template->yield() (line 1 of core/themes/olivero/components/teaser/teaser.twig).
    Drupal\Core\Theme\Component\ComponentValidator->validateProps() (Line: 127)
    Drupal\Core\Template\ComponentsTwigExtension->doValidateProps() (Line: 109)
    Drupal\Core\Template\ComponentsTwigExtension->validateProps() (Line: 52)
    __TwigTemplate_6b0fecdcfa442453874f681702db33fb->doDisplay() (Line: 393)
    Twig\Template->yield() (Line: 80)
    __TwigTemplate_381600d8b2a74e1648ca6b760fdfea2d->doDisplay() (Line: 393)
    Twig\Template->yield() (Line: 349)
    Twig\Template->display() (Line: 364)
    Twig\Template->render() (Line: 35)
    Twig\TemplateWrapper->render() (Line: 234)
    Drupal\Core\Template\TwigEnvironment->renderInline() (Line: 160)
    Drupal\dab\Controller\DabComponentController->embed()
    call_user_func_array() (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 638)
    Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 121)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
    Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 53)
    Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
    Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
    Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 106)
    Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
    Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
    Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 741)
    Drupal\Core\DrupalKernel->handle() (Line: 19)
    <code>
    
    Here's a one-liner to quickly get UI Suite USWDS running:
    
    <code>
    ddev composer require drupal/layout_options drupal/ui_styles drupal/ui_suite_uswds; ddev drush en layout_options ui_icons_patterns -y; ddev drush then ui_suite_uswds -y; ddev drush config:set system.theme default ui_suite_uswds -y;
    
  • πŸ‡«πŸ‡·France Quentin Harelle

    I'm missing something in your dependencies here.

    I could only install drupal/ui_suite_uswds:^3.0@alpha with a fresh D10 install.
    Once this ok I had this issue : Unable to install modules layout_options, ui_icons_patterns due to missing modules ui_icons_patterns.

    Can you provide all the dependencies needed to make this work please ?

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

    Sorry, my previous comment wasn’t formatted correctly. Fixed. It includes composer command for the required modules.

  • πŸ‡«πŸ‡·France Quentin Harelle

    I saw the installing lines and thank you for providing it. But I am sorry I am still having issues installing your suite of modules ...

    After the ddev composer require drupal/layout_options drupal/ui_styles drupal/ui_suite_uswds; I have this issue :
    Unable to install modules: module 'ui_icons_patterns'. Its dependency module 'ui_icons' is incompatible with this version of Drupal core.

    I'm using minimal alpha version in composer requirements and I am with Drupal 10.3.11 as you said in you first comment. I also tried other stuff to make it work but ui_icons is still the issue.

Production build 0.71.5 2024