Make DirectoryWithMetadataDiscovery generic and reusable

Created on 18 September 2024, about 2 months ago

Problem/Motivation

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

It allows discovering a single plugin within a specific discovery. 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.

📌 Task
Status

Active

Version

11.0 🔥

Component
single-directory components 

Last updated about 16 hours ago

Created by

🇫🇷France pdureau Paris

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

Comments & Activities

  • Issue created by @pdureau
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
    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.
  • 🇫🇷France pdureau Paris

    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 planned to use Drupal\Core\Plugin\Discovery\DirectoryWithMetadataDiscovery to load them.

    I can see other modules, contrib or custom, which would want to load a plugins from {drupal_extension}/predefined/path{plugin_id}/{plugin_id}.{plugin_type}.yml

    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';
    
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

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

Production build 0.71.5 2024