As a follow-up of #3413130: SDC components: Fix JSON schema usage, here are some feedbacks done with https://www.drupal.org/project/sdc_devel which is providing a drush command and a report page to audit SDC components.
Unused variables
Every slot or prop from the component definition must be used in templates.
Default attributes object is not always defined in the YAML, but always injected in template and expected for alteration (adding contextual accessibility attributes, adding data for site building tools, style overrides of the component...).
$ vendor/bin/drush sdcv --install prototype | grep "Unused variables:"
[notice] Start validation of prototype...
menu-tabs Unused variables: attributes
back-to-top Unused variables: attributes
search-bar Unused variables: attributes, form_action, form_children
slideshow Unused variables: index_id, title
icons Unused variables: attributes
Unknown variables
Every slot or prop used in the template must be found in the component definition (except the ones automatically injected: attributes, componentMetadata...)
$ vendor/bin/drush sdcv --install prototype | grep "Unknown variable:"
[notice] Start validation of prototype...
search-bar Unknown variable: `button_text`. 12 {{ button_text|default('Expand Search') }}
search-bar Unknown variable: `button_text`. 12 {{ button_text|default('Expand Search') }}
search-bar Unknown variable: `content`. 16 {{content}}
slideshow Unknown variable: `options`. 26 {% set data_splide = options|default({})|merge(default_options) %}
slideshow Unknown variable: `options`. 26 {% set data_splide = options|default({})|merge(default_options) %}
slideshow Unknown variable: `heading`. 30 <h2 id="{{label_id}}" class="c-slideshow__heading visually-hidden">{{
slideshow Unknown variable: `heading`. 30 <h2 id="{{label_id}}" class="c-slideshow__heading visually-hidden">{{
slideshow Unknown variable: `slides`. 34 {% for slide in slides %}
menu Unknown variable: `classes`. 2 'class': ['c-menu']|merge(classes|default([])),
menu Unknown variable: `classes`. 2 'class': ['c-menu']|merge(classes|default([])),
menu Unknown variable: `menu_name`. 19 {{ menus.menu_links(items, attributes.addClass('c-menu__list'), 0, menu_name) }}
menu Unknown variable: `classes`. 25 <li {{ item.attributes.addClass(classes) }}>
drupal-messages Unknown variable: `status_headings`. 10 <div role='contentinfo' aria-label="{{ status_headings[type] }}" {{
drupal-messages Unknown variable: `status_headings`. 15 {% if status_headings[type] %}
drupal-messages Unknown variable: `status_headings`. 16 <h2 class='visually-hidden'>{{ status_headings[type] }}</h2>
sidebar Unknown variable: `class`. 2 <aside{{attributes.addClass(class)}} role='complementary'>
Incomplete prop definitions
Empty objects are not enough to be understood and processed by display builders (UI Patterns 2, the upcoming Experience Builder...):
$ vendor/bin/drush sdcv --install prototype | grep "Empty array"
[notice] Start validation of prototype...
teaser Empty array. 23 media:
pager Empty array. 11 items:
pager Empty array. 14 ellipses:
tabs-content Empty array. 14 items: Issue fork prototype-3502491
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
jldust commentedComment #6
grgcrlsn321 commentedI've added props and updated props that needed fixed.
YAML fixes — wrong prop names replaced:
button.component.yml — replaced icon with icon_prefix and icon_suffix
slideshow.component.yml — replaced title with heading, options, and slides
search-bar.component.yml — replaced form_action and form_children with prop button_text and slot content
breadcrumbs.component.yml — renamed slot breadcrumbs_block → items_block, added prop id
YAML additions — missing props added:
menu.component.yml — added menu_name and classes
sidebar.component.yml — added class
Twig fixes — dead variables removed:
pager.twig — removed {% set is_current %} (never output; aria-current already written inline)
slideshow.twig — removed {% set index_id %} (never referenced in template output)
Twig workaround — macro-only component:
icons.twig — added {% if attributes %}{% endif %} to satisfy the validator for the auto-injected attributes variable in a macro-only file
Comment #7
grgcrlsn321 commentedComment #8
grgcrlsn321 commentedFixes:
This fixes the remainder of the errors on this issue. Setting to needs review.
Comment #9
grgcrlsn321 commentedI had a workaround for the icons component, but I don't think it's that great and could cause more confusion. There aren't any attributes for that component so creating an if statement is not very helpful for it's use case. That means, there is still a warning that we should ignore:
Comment #10
pdureau commentedMaybe because this component is not... a component ;) Why not using the Core Icon API to manage this?
Comment #11
grgcrlsn321 commentedComment #12
grgcrlsn321 commentedokay, I went ahead and moved icons to a macros directory to not include it with the components. This removes the warnings and defines the macro more clearly. We can't fully support the Core Icon API with Drupal sites using 10.3. Maybe in a future upgrade and we drop 10.3 support we can look at using Core Icon API. Setting to needs review.
Comment #13
jldust commentedI removed the macro in favor of the updated icons component, going to need additional testing to confirm this is the direction we want to go for now. I think we should create another issue for reviewing the Core Icon API option.
Comment #14
pdureau commentedUI Icons module has a copy of the Drupal 11.x Icon API in its 1.0.x branch, to be used with Drupal 10.x
Comment #15
jldust commentedNoting that I've created a dedicated issue for us to look into Drupal Icons API and how to support that.
Comment #16
jldust commentedThis has been merged in and will be included in the next tagged release.
Comment #18
jldust commentedComment #20
jldust commented