- Issue created by @just_like_good_vibes
- Merge request !353Issue #3513568 by just_like_good_vibes: Source usability : better interfaces for sources relying on child plugins β (Closed) created by just_like_good_vibes
- π«π·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 :)
- Merge request !418Resolve #3513568 "Source with choices" β (Merged) created by just_like_good_vibes
- π«π·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:cardBlockSource with
system_menu_block:admin:source_id: block source: plugin_id: system_menu_block:adminExpected 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
3 months ago 7:59am 9 August 2025 - π«π·France pdureau Paris
Thanks for your ongoing work.
It would be nice to also implement this interface on
ComponentSourceso it will be possible to get the same simplification in display_builder'sComponentLibraryPanel.Also, we may need to add some properties in ::getChoices() along side
labelandprovider: 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
labelandgroup/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. -
pdureau β
committed d8736376 on 2.0.x authored by
just_like_good_vibes β
Issue #3513568 by just_like_good_vibes, pdureau: Add...
-
pdureau β
committed d8736376 on 2.0.x authored by
just_like_good_vibes β
Automatically closed - issue fixed for 2 weeks with no activity.