Problem/Motivation
I am trying to convert my SDC components to work with UI Patterns.
I am struggling with this error message:
Drupal\Core\Render\Component\Exception\InvalidComponentException: [attributes] String value found, but an object is required in Drupal\Core\Theme\Component\ComponentValidator->validateProps() (line 203 of core/lib/Drupal/Core/Theme/Component/ComponentValidator.php).
These are difficult to troubleshoot and I want to ask for some help with how to approach these.
Previously, I have just removed any `attributes` props in my components.
But now I have a complex component with nested components. Even removing all nested components I still get the "[attributes] string value found .." exception.
Steps to reproduce
If I understood this I could probably find a solution, but here an excerpt:
region-header.html.twig
{% include 'header.twig' with {
is_front,
active_language,
header_menu,
} only %}
header.twig
{% embed 'my_components:header' with {
} %}
{% endembed %}
my_components/components/header.component.yml
$schema: https://git.drupalcode.org/project/sdc/-/raw/1.x/src/metadata.schema.json
name: Header
props:
type: object
properties: {}
my_components/components/header.twig
<div{{ attributes.addClass("header") }}>
</div>
Drupal\Core\Render\Component\Exception\InvalidComponentException: [attributes] String value found, but an object is required in Drupal\Core\Theme\Component\ComponentValidator->validateProps() (line 203 of core/lib/Drupal/Core/Theme/Component/ComponentValidator.php).
Drupal\Core\Template\ComponentsTwigExtension->doValidateProps(Array, 'my_components:header') (Line: 110)
Drupal\Core\Template\ComponentsTwigExtension->validateProps(Array, 'my_components:header') (Line: 174)
__TwigTemplate_c66bd735bef21e8d7bcb996aa6416374___692438094->doDisplay(Array, Array) (Line: 388)
Twig\Template->yield(Array) (Line: 63)
__TwigTemplate_c66bd735bef21e8d7bcb996aa6416374->doDisplay(Array, Array) (Line: 388)
Twig\Template->yield(Array) (Line: 924)
__TwigTemplate_96b869eb9d8bd0d227e4ddd466a0b907___490765172->block_header(Array, Array) (Line: 432)
Twig\Template->yieldBlock('header', Array, Array) (Line: 124)
__TwigTemplate_ac02a7169598bf0844fd67f0fd02cc8c->doDisplay(Array, Array) (Line: 388)
Twig\Template->yield(Array, Array) (Line: 910)
__TwigTemplate_96b869eb9d8bd0d227e4ddd466a0b907___490765172->doDisplay(Array, Array) (Line: 388)
Twig\Template->yield(Array) (Line: 85)
__TwigTemplate_96b869eb9d8bd0d227e4ddd466a0b907->doDisplay(Array, Array) (Line: 388)
Twig\Template->yield(Array, Array) (Line: 344)
Twig\Template->display(Array) (Line: 359)
Twig\Template->render(Array) (Line: 51)
Twig\TemplateWrapper->render(Array) (Line: 37)
twig_render_template('themes/custom/mytheme/templates/layout/region--header.html.twig', Array, Array) (Line: 426)
...
Proposed resolution
Guidance on how to define attributes, use {% embed only %}
Remaining tasks
User interface changes
API changes
Data model changes