Problem/Motivation

We are planning to rewrite UI Patterns upon SDC. To achieve this, we are proposing a few changes and additions:


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

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:

  • 3391978-sdc-add-a Comparechanges, plain diff MR !6070
  • 1 hidden branch
  • 11.x Comparecompare

Comments

pdureau created an issue. See original summary.

idiaz.roncero’s picture

+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 to getAllComponents(TRUE) or similar are harder to read and understand at first sight for newcomers.

e0ipso’s picture

I 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.

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

oldeb’s picture

Version: 10.1.x-dev » 11.x-dev
Assigned: Unassigned » oldeb

oldeb changed the visibility of the branch 11.x to hidden.

grimreaper’s picture

Status: Active » Needs work
Issue tags: +Needs tests

Created the MR because oldeb was not able to, maybe due to missing permissions. I was with him in video meeting.

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.