Skip to content

Extend Display Builder with source plugins

Source plugins are managed by UI Patterns 2. See UI Patterns 2 documentation.

Source plugin for slots

A source plugin targeting slot prop type:

namespace Drupal\my_module\Plugin\UiPatterns\Source;

use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\ui_patterns\Attribute\Source;
use Drupal\ui_patterns\SourcePluginBase;

#[Source(
  id: 'my_source',
  label: new TranslatableMarkup('My slot source'),
  prop_types: ['slot']
)]
class MySource extends SourcePluginBase {
}

.. will show up in the Blocks library panel, grouped by its category:

Source slots

Source configuration from PluginSettingsInterface::settingsForm() is available in the Config contextual panel. For example:

Source slots configuration

A source targeting string also reaches the Blocks library, through UI Patterns' string-to-slot conversion, on top of appearing in the Source select of every string prop.

Source plugins for props

They are displayed in the component form managed by UI Patterns 2. Display Builder is doing nothing specific here.

Hiding a source from the Blocks library

The Blocks library panel drops a few sources that make no sense there, or that Display Builder supersedes: component, token (deprecated in UI Patterns, Textfield takes tokens) and wysiwyg (superseded by Textarea). Sources provided by ui_patterns_blocks are dropped too. The list lives in BlockLibraryPanel, alongside two admin-configurable exclusions in the island's configuration form: by module (exclude) and by source ID, one per line (exclude_id).

Sources shipped by Display Builder

Display Builder ships two sources of its own, and swaps the class of two UI Patterns ones rather than adding a competing source, so a stored display keeps working either way:

Source Prop types What it is
textarea string, identifier Rich text, see Rich text with Textarea
layout slot A Drupal layout plugin, with its regions as slots. Needs layout_discovery
component slot UI Patterns' component source, with builder specific rendering
block slot UI Patterns' block source, with builder specific rendering

component and layout implement SourceWithSlotsInterface: a source with nested slots, their values and cardinality (getSlotCardinality()) exposed to the builder. Implement it for a new source holding slots.

See also