Create new SDC component for Olivero (header-search)

Created on 14 March 2023, almost 2 years ago
Updated 17 July 2024, 5 months ago

Problem/Motivation

Single directory components (SDC) is a new way to theme Drupal. Instead of scattering related files around your theme, they're contained to one directory. The primary issue for SDC is at Single directory components in core Active

While reviewing this proposal and related issues I wanted to port an existing component to get a feel for the workflow.

This issue is of course blocked on actually getting SDC into core. See Add Single Directory Components as a new experimental module Fixed .

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

📌 Task
Status

Needs work

Version

11.0 🔥

Component
Olivero 

Last updated 4 days ago

Created by

🇦🇺Australia mstrelan

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.

  • Issue created by @mstrelan
  • 🇦🇺Australia mstrelan

    Some observations.

    The first issue I ran in to was this error:

    Twig\Error\SyntaxError: An exception has been thrown during the compilation of a template ("We found an unexpected slot that is not declared: [content]. Please declare them in "search-form.component.yml".") in "olivero:search-form". in Twig\Environment->compileSource() (line 524 of /data/vendor/twig/twig/src/Environment.php).

    What is a slot? Where do I find information on slots? After some poking around I eventually realised it refers to {% block content %} in the twig template. I had a look at the schema and found slots next to props with the same schema so I added slots to my yaml file. Since it takes the same schema as props I just copy/pasted that directly and left only the content property. That lead to the following error:

    Drupal\sdc\Exception\InvalidComponentException: Slots can only be declared with the type "string". Slot [content] in component "header-search-narrow" is declared with type "array". in Drupal\sdc\Component\ComponentMetadata->parseSchemaInfo() (line 178 of core/modules/sdc/src/Component/ComponentMetadata.php). 
    

    OK, so it can only be a string, what's the point declaring its type if it can only ever be "string"?

    The next thing I wondered, do I really have to pass all the variables from one twig to another? And do I need to declare the props for title_prefix, title_suffix, attributes, etc? I've declared them all, but opted not to pass them from the original twig files as that seems to happen automatically.

    The final challenge I faced was that the order of the CSS files that were loaded had changed. This meant that the primary button hover/focus/active styles were taking precedence over the custom styles for the search submit button. For now I've added explicit hover/focus/active styles for this button, but it seems we could also just remove the button--primary class.

    I also added a @todo comment in the MR wondering if there is a better SDC way of doing this:

    $variables['content']['actions']['submit']['#theme_wrappers'] = ['input__submit__header_search'];

  • e0ipso Can Picafort

    This is great feedback! Do you mind if I quote you in the SDC MR so we can talk about it there?

  • 🇦🇺Australia mstrelan

    No problem at all. I also raised a number of issues against cl_server and sdc_examples modules, but these are less relevant for core.

  • Status changed to Needs work over 1 year ago
  • e0ipso Can Picafort

    Unblocking this after SDC got merged into Drupal core.

  • First commit to issue fork.
  • Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    Not currently mergeable.
  • Status changed to Needs review over 1 year ago
  • 🇮🇳India gauravvvv Delhi, India
  • Status changed to Needs work over 1 year ago
  • e0ipso Can Picafort

    I added some comments and suggestions in the MR.

  • First commit to issue fork.
  • Pipeline finished with Failed
    5 months ago
    Total: 641s
    #226267
Production build 0.71.5 2024