Problem/Motivation

Pattern presets config entities have a "group" property which is a simple (translatable?) string:

id: 68679ab4e1797
label: "My button with a title"
description: ""
group: ""
theme: usb_sub
sources: [...]

But it is not used anywhere.

Proposed resolution

Among the patterns showing up in the Pattern Libray panel (not all patterns are displayed here all the time, because of #3534190: Pattern presets storage and dependencies):

  • group them by group. Patterns without groups go to "Others"
  • if there is only group after the grouping, flat the list instead of keeping the group
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.

pdureau’s picture

Issue tags: +Novice
juc1’s picture

Assigned: Unassigned » juc1

juc1’s picture

Assigned: juc1 » Unassigned
Status: Active » Needs review
pdureau’s picture

pdureau’s picture

Status: Needs review » Needs work

Hi @juc1, thanks for the work, can you:

  • fix pipelines errors (mostly phpcs)?
  • move group logic to its own protected property in PresetLibraryPanel?

The prefill of group value with the SDC group is unexpected but looks like a good idea :) Maybe we can do the same with other sources ?

  • if Drupal block plugin, the block category
  • for other slot sources, just the source label

Then, users will be able to edit the group in admin UI anyway.

juc1’s picture

ok will update...

pdureau’s picture

juc1’s picture

@Pierre is it ok now? or let me know anything else...

juc1’s picture

Status: Needs work » Needs review
pdureau’s picture

Status: Needs review » Postponed (maintainer needs more info)
Issue tags: -Novice

Hi @juc1,

Thanks for your proposal and proposing cool additional mechanisms like the prefill of the value. It is very lovely.

Review

However, I am a bit concerned this little feature became a +233 LOC addition with:

  • a ComponentPluginManager dependency in ApiController
  • some ComponentSource data structure logic in ApiController::saveAsPreset()
  • a ComponentPluginManager dependency in PresetLibraryPanel

We need to keep parts of the architecture cleanly separated. ApiController and PresetLibraryPanel must not be aware of ComponentPluginManager and ComponentPluginManager, because there must be the Source API as a proxy in-between.

Proposal

What do you think about proposing to UI Patterns' team to add something like:

Method In Library panels Preset creation
SourceInterface::getGroup(array $data = []): string to group the source with other source plugins To set the default value of the preset group
SourceWithChoicesInterface::getGroupedChoices(): array To split the choices of a single source plugin in many groups No expected usage

So:

  • your PresetLibraryPanel::getComponentPresetGroup() can become SourceComponentSource::getGroup()
  • your PresetLibraryPanel::getBlockPresetGroup() can become BlockSource::getGroup()
  • your PresetLibraryPanel::getOtherSourcePresetGroup() can become SourcePluginBase::getGroup()

That's all for the scope of this issue. After that, we can create a follow-up ticket to use the new methods to get rid of BlockLibrarySourceHelper because most of the logic here will reside in Source plugins themselves.

Let's discuss :)

pdureau changed the visibility of the branch 3534217-use-groups-in to hidden.

pdureau changed the visibility of the branch 1.0.x to hidden.

juc1’s picture

@ Pierre yes of course you are right - display_builder should not be trying to work out group id's. Instead it should be asking ui_patterns for the group id. Shall I open an issue in ui_patterns to add the two new methods to the api so that ui_patterns can provide the group id?

pdureau’s picture

Assigned: Unassigned » pdureau
Status: Postponed (maintainer needs more info) » Needs work

Hi @juc1,

I will push an additional commit to your MR with the move of the logic.

We have a look together. If we like that, we create an UIP2 issue with the proposal.

pdureau’s picture

Assigned: pdureau » Unassigned

Back to Juc1 :)

A little tip: you can move the initialization logic from ApiController to PatternPreset entity by making $group nullable:

-  protected string $group = '';
+  protected ?string $group = NULL;

and extending ::getGroup() method:

   public function getGroup(): string {
    if (is_null($this->group) && isset($this->sources['source_id'])) {
      $configuration = [
        'settings' => $this->sources['source'] ?? [],
      ];
      /** @var \Drupal\ui_patterns\SourceInterface $source */
      $source = $this->sourcePluginManager()->createInstance($this->sources['source_id'], $configuration);
      $this->group = $source->getGroup();
    }
     return $this->group;
  }
pdureau’s picture

We will also need a unit test for this

juc1’s picture

Status: Needs work » Needs review
pdureau’s picture

Assigned: Unassigned » pdureau

Thanks, i will have a look and add a commit with the documentation update.

pdureau’s picture

Status: Needs review » Needs work

Thanks for the incredible work, with a lot of clear comments and a kenrel test.

I will do 4 little changes before RTBC:

  • a little documentation update
  • run php-cs-fixer (not mandatory but some team members run this linter locally, so it will make their life easier)
  • an implementation of ::getGroup() in \Drupal\display_builder\Plugin\UiPatterns\Source\ComponentSource (this class is temporary, it will be move to UI Pattenrs later, but it will already be useful to get the implementation)
  • a logic change: once saved in the config entity, the group must not be automatically changed, even if the ::getGroup() logic change. ::getGroup() is used only when creating the pattern preset.
pdureau’s picture

Assigned: pdureau » mogtofu33
Status: Needs work » Reviewed & tested by the community

We did it!

juc1’s picture

💪😍

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

mogtofu33’s picture

Assigned: mogtofu33 » Unassigned
Status: Reviewed & tested by the community » Needs work

Added a better cache for presets to avoid too much cache when refreshing a Display.
Removed a lot of comments, refactor some nested code, please keep it clean and simple.
When using AI please review beforehand.

Needs to work on this source::getGroup() which needs to be removed if not used as it is now.

  • mogtofu33 committed 542d1518 on 1.0.x authored by juc1
    feat: #3534217 Use groups in Pattern presets library
    
    By: pdureau
    By:...
mogtofu33’s picture

Status: Needs work » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.