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
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
Comment #2
wim leersComment #3
pdureau commentedsdc_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}.ymlbecause 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\Pluginnamespace, have a string (a single string!) tied to SDC:Comment #4
wim leersThat makes sense! :) Thanks for explaining! I think that'll convince core committers too :)
Comment #5
nod_You can probably add XB to the list too :)
Comment #6
pdureau commentedComment #8
pdureau commentedComment #11
pdureau commentedThanks Daniela.
Pipeline is OK. I will test it with a real life project :)
Comment #12
pdureau commentedOK 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.