[2.0.3] Source usability : better interfaces for sources relying on child plugins

Created on 17 March 2025, 5 months ago

Problem/Motivation

UI pattern sources like component or blocks, rely on child plugins.
should have :
- an interface (and factorized implementation like a trait?) to allow to fetch the list of child plugins from outside the source.
- improved source label when child plugin is selected
- settings presets/skeletons for a source when a child plugin is known.

πŸ“Œ Task
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡«πŸ‡·France just_like_good_vibes PARIS

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

Merge Requests

Comments & Activities

  • Issue created by @just_like_good_vibes
  • Pipeline finished with Success
    5 months ago
    Total: 913s
    #450749
  • πŸ‡«πŸ‡·France pdureau Paris

    I am not sure about the naming...

    Proposal inspired from [ObjectWithPluginCollectionInterface](https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Plugin%21...) but not identical because we have a single collection and not many collections:

    interface SourceWithCollectionInterface {
    
      /**
       * Get collection of items.
       *
       * @return array
       *   Array of items definitions.
       */
      public function getCollection(): array;
    
      /**
       * Get the minimal source configuration for an item.
       *
       * @param string $item_id
       *   An item ID.
       *
       * @return array
       *   A source configuration.
       */
      public function getSourceConfiguration(string $item_id): array;
    
      /**
       * Get the currently select item from the collection.
       *
       * @return string|null
       *   The item ID.
       */
      public function getSelectedItem(): ?string;
    

    Do we also need a getItemLabel(string $item_id): string ?

  • πŸ‡«πŸ‡·France just_like_good_vibes PARIS

    getMinimalConfiguration does not need any parameter, unless it is static, which could be a nice idea after all.

    i don’t like collection, because it reminds of the plugin collections in drupal which are managed differently…

  • πŸ‡«πŸ‡·France just_like_good_vibes PARIS

    also, the term configuration for the source refers to the global configuration, whereas we wanted the settings, i would keep settings to avoid confusion

  • πŸ‡«πŸ‡·France pdureau Paris

    getMinimalConfiguration does not need any parameter, unless it is static, which could be a nice idea after all.

    Oops, a copy paste mistake, I fix it in my comment

  • πŸ‡«πŸ‡·France pdureau Paris
    • getChildPluginDefinitions >> getItems
    • getSettingsSourceWithChildPlugin >> getMinimalSetting
    • getChildPluginId >>getSelectedItem
    interface SourceWithItemsInterface {
    
      /**
       * Get items.
       *
       * @return array
       *   Associative array of items definitions with ID as the key.
       */
      public function getItems(): array;
    
      /**
       * Get the minimal settings for an item.
       *
       * @param string $item_id
       *   An item ID.
       *
       * @return array
       *   A source setting.
       */
      public function getMinimalSetting(string $item_id): array;
    
      /**
       * Get the currently select item.
       *
       * @return string|null
       *   The item ID.
       */
      public function getSelectedItem(): ?string;
    

    Is it better?

    Also:

    • Do we also need a getItemLabel(string $item_id): string ?
    • it may be good to move ::getMinimalSetting() to SourceInterface and to implemtn it in SourcePluginBase as a proxy to PluginSettingsInterface::defaultSettings(). What do you think?
  • πŸ‡«πŸ‡·France just_like_good_vibes PARIS

    i am not so fan of items neither :)

  • Pipeline finished with Success
    4 months ago
    Total: 176s
    #492104
  • πŸ‡«πŸ‡·France pdureau Paris
  • πŸ‡«πŸ‡·France pdureau Paris

    Too late for 2.0.X

  • Pipeline finished with Skipped
    3 months ago
    #515113
  • πŸ‡«πŸ‡·France pdureau Paris
  • πŸ‡«πŸ‡·France pdureau Paris
  • πŸ‡«πŸ‡·France pdureau Paris

    UI Patterns 2 sources where we want to extract multiple item.

    Reminder: Only for slots source.

    Nice to have

    ComponentSource with bootstrap:card:

    source_id: component
    source:
      component: 
        component_id: bootstrap:card
    

    BlockSource with system_menu_block:admin:

    source_id: block
    source:
      plugin_id: system_menu_block:admin
    

    Expected in the scope of this issue

    Entity Field with field:node:article:title:

      source_id: entity_field
      source:
        derivable_context: 'field:node:article:title'
        'field:node:article:title':
          value: {}
    

    Entity Reference with entity_reference:node:article:uid:user:user:

      source_id: entity_reference
      source:
        derivable_context: 'entity_reference:node:article:uid:user:user'
        'entity_reference:node:article:uid:user:user':
          value: {}
    

    Out of scope

    Because single item:

    • WysiwygWidget
    • TokenSource
    • ViewRowsSource

    Multiple items context never reached from the top of a component data tree:

    • ViewFieldSource
    • FieldFormatterSourceDeriver
  • Status changed to Needs work 16 days ago
  • πŸ‡«πŸ‡·France pdureau Paris

    Thanks for your ongoing work.

    It would be nice to also implement this interface on ComponentSource so it will be possible to get the same simplification in display_builder's ComponentLibraryPanel.

    Also, we may need to add some properties in ::getChoices() along side label and provider: like the original plugin ID and the group/category.

    It would be even better to return an object implementing standard interfaces instead of a loose array:

    • PluginDefinitionInterface::getClass
    • PluginDefinitionInterface::getProvider
    • PluginDefinitionInterface::id
    • PluginDefinitionInterface::setClass
    • Unfortunately, I have found nothing for label and group/category

    Can you also add this to EntityReferencedSource or DerivableContextSourceBase ?

    +  /**
    +   * {@inheritdoc}
    +   */
    +  public function settingsSummary(): array {
    +    $derivable_context = explode(':', $this->getSetting("derivable_context") ?? '');
    +    return [
    +      $derivable_context[array_key_last($derivable_context)],
    +    ];
    +  }
  • πŸ‡«πŸ‡·France just_like_good_vibes PARIS

    just_like_good_vibes β†’ changed the visibility of the branch 3513568-2.0.3-source-usability to hidden.

  • πŸ‡«πŸ‡·France just_like_good_vibes PARIS

    here we are, ready for review :

    - we have a new interface for those sources with a choice. It allows them to expose those choices to the outside world.
    - we have improved the returned label of sources, in those particular cases of sources with choice.

  • πŸ‡«πŸ‡·France pdureau Paris
  • πŸ‡«πŸ‡·France pdureau Paris
Production build 0.71.5 2024