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

Comments

oldeb created an issue. See original summary.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.