Problem/Motivation
We are planning to rewrite UI Patterns upon SDC. To achieve this, we are proposing a few changes and additions:
- #3390980: Make SDC extensible
- #3352063: Allow schema references in Single Directory Component prop schemas
- #3390712: Add component variants to SDC
- #3390717: Allow declaration of template path in SDC
- #3391702: SDC ComponentElement: Transform slots scalar values to #plain_text instead of throwing an exception
- Add a method to retrieve only components not replaced by others. The current issue
ComponentPluginManager::getAllComponents() is useful to retrieve all the components.
However, we sometimes needs a list of the components minus the ones replaced by others. For example:
- An UI for selecting components while doing site building
- A library page
- Some controls in code
A replaced component is not "active" anymore, so it makes little sense to display it.
Proposed resolution
Add a boolean parameter to ComponentPluginManager::getAllComponents():
public function getAllComponents(bool $filter = FALSE): array {
For better control, this parameter can be an integer like what is done in StreamWrapperManagerInterface::getWrappers:
public function getAllComponents(int $filter = 0): array {
Or add a new public function to ComponentPluginManager:
public function getActiveComponents(): array {
I guess "active" a good keyword for components which are not replaced by others. So, we can add other unrelated rules later (according to some status or conditions).
Remaining tasks
If there is a chance for this feature to be accepted, we (UI Patterns team) can propose a merge request soon.
We have one month before the release of Drupal 10.2.0-alpha1.
Issue fork drupal-3391978
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
idiaz.roncero+1 to this.
Also, for readability and clarity I think the new public method (
getActiveComponents) is the best solution. Boolean flags tend to obfuscate what's happening, calls togetAllComponents(TRUE)or similar are harder to read and understand at first sight for newcomers.Comment #3
e0ipsoI like this proposal. Let's keep in mind that active component depends heavily on the active theme. This is often overlooked, and specially frustrating when listing the components for an admin screen (that is rendered using an admin theme).
Perhaps we ought to add a parameter
getActiveComponents(using_theme: 'olivero'). Where the default parameter uses the currently active theme.Comment #5
oldebComment #8
grimreaperCreated the MR because oldeb was not able to, maybe due to missing permissions. I was with him in video meeting.