Problem/Motivation

Drupal\Core\Plugin\Discovery\DirectoryWithMetadataDiscovery is a nice feature added by SDC.

It allows discovering a single plugin within a specific directory. The definition is still a YAML, but anything in the discovery belong to the plugin and can be checked and loaded.

It could be useful for many projects.

However, there is some stuff related to SDC hardcoded, which is surprising for a code living in the Drupal\Core\Plugin namespace:

    // Detect "my_component.component.yml".
    $regex = '/^([a-z0-9_-])+\.component\.yml$/i';
 

Proposed resolution

Remove information related to SDC and inject it from "outside"

Drupal\Core\Plugin\Discovery\DirectoryWithMetadataDiscovery is only called by Drupal\Core\Plugin\Discovery\DirectoryWithMetadataPluginDiscovery which is only called by Drupal\Core\Theme\ComponentPluginManager.

So, the data will need to be passed through DirectoryWithMetadataPluginDiscovery.

User interface changes

No

API changes

I believe this change can be done without breaking anything.

Issue fork drupal-3475153

Command icon 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

pdureau created an issue. See original summary.

wim leers’s picture

  1. What contrib modules are waiting for this?
  2. In Drupal core, we generally only introduce an abstraction once there's >=3 uses for it.
pdureau’s picture

Issue summary: View changes

What contrib modules are waiting for this?

sdc_styleguide and UI Patterns 2.x's ui_patterns_library sub-module are working on a common stories format and we are planning to use Drupal\Core\Plugin\Discovery\DirectoryWithMetadataDiscovery to load them.

I can imagine other modules, contrib or custom, which would want to load a plugins from {drupal_extension}/predefined/path/{plugin_id}/{plugin_id}.{plugin_type}.yml because it is a convenient and powerful mechanism.

Anyway, even if it is not useful for anybody, we have this weird situation to address where 2 discovery classes which are not looking related to SDC, not documented as part of SDC, and located in the Drupal\Core\Plugin namespace, have a string (a single string!) tied to SDC:

    // Detect "my_component.component.yml".
    $regex = '/^([a-z0-9_-])+\.component\.yml$/i';
wim leers’s picture

That makes sense! :) Thanks for explaining! I think that'll convince core committers too :)

nod_’s picture

You can probably add XB to the list too :)

pdureau’s picture

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.

pdureau’s picture

danieazc made their first commit to this issue’s fork.

pdureau’s picture

Assigned: Unassigned » pdureau
Status: Active » Needs review
Issue tags: +Chicago2026

Thanks Daniela.

Pipeline is OK. I will test it with a real life project :)

pdureau’s picture

Assigned: pdureau » Unassigned
Status: Needs review » Reviewed & tested by the community

OK for me, but I have added an extra commit to the MR so it may be a good idea to have an additional review by someone else.