Allow different methods of discovery for SDC components

Created on 4 March 2023, over 1 year ago
Updated 19 April 2023, over 1 year ago

Problem/Motivation

To better support external components or components that are defined in files other than *.component.yml it would be great if the discovery system for SDC was pluggable so contrib can provide additional ways to define components outside of *.component.yml files in modules and themes.

My main use case is to have components defined using json as non Drupal frontend developers are usually more familiar with json and json is better supported in other frontend tooling.

Proposed resolution

Create a new Component Discovery plugin system that is used by the ComponentPluginManager to discover component definitions. The current usage of DirectoryWithMetadataPluginDiscovery would be moved to a YamlDiscovery plugin.

For the ComponentDiscovery plugin definition I'm thinking

/**
 * @ComponentDiscovery(
 *   id="",
 *   label=@Translation(""),
 *   plugin_class="",
 *   weight=0
 * )
 */
  • id: Self explanatory, the machine id of the plugin
  • label: Self explanatory, the label the plugin should it ever be exposed in an interface
  • plugin_class: This would be the class for the plugins defined by the discovery method. SDC currently defaults `class` to `\Drupal\sdc\Plugin\Component` and this would allow for components using other discovery methods to easily use a new class with different logic for the base functions or to have additional helper functions.
  • weight: Not 100% on this one. It could make sense to allow weighting/priority of the discovery methods but I think the component negotiator may already handle this sufficiently

It'll also be important to make sure the rest of SDC doesn't make any assumptions about where components can come from. Mainly that it doesn't assume components are sourced from a yml file or that component files are necessarily in a module/theme directory.

Feature request
Status

Fixed

Version

10.1

Component
Render 

Last updated 9 days ago

Created by

🇺🇸United States ctrladel North Carolina, USA

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024