Error when creating a component without template

Created on 26 April 2024, 2 months ago
Updated 18 June 2024, 8 days ago

Problem/Motivation

WSOD when creating a component YAML file without template.

Steps to reproduce

  • Fresh Drupal install (10.2) & SDC enabled
  • Create and enable as default a new "mytheme" (sub-)theme
  • Create a new "my-component" component (yaml + twig)
  • Display the "my-component" component in a twig template using the include() method
  • Create a new "another-component" component without template (yml only)
  • Rebuild cache

Expected result: page loads correctly

Actual result :

  • Drupal\sdc\Exception\InvalidComponentException: Unable to find the Twig template for the component "mytheme:another-component"
  • Deprecated function: basename(): Passing null to parameter #1 ($path) of type string is deprecated in Drupal\sdc\ComponentPluginManager->alterDefinition() (line 323 of core/modules/sdc/src/ComponentPluginManager.php).

I feel like adding a valid yml file without a template should not throw an error.

Proposed resolution

Allow to add valid .component.yml files without throwing an error, if template is missing then component should just be ignored.

Remaining tasks

  • Add a if statement around the basename($template) call to avoid deprecation warning
  • Remove the definition from the definitions array is no template is provided

User interface changes

None

API changes

None

Data model changes

None

Release notes snippet

None

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component
single-directory componentsΒ  β†’

Last updated about 21 hours ago

Created by

πŸ‡§πŸ‡ͺBelgium oldeb Brussels

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

Comments & Activities

Production build 0.69.0 2024