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

Created on 17 March 2025, 16 days 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
    16 days 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 :)

Production build 0.71.5 2024