This module provides special form fields for embedding plugin configurations within Drupal forms. It allows you to include a form for a single pre-selected plugin or a more dynamic interface where users can add, configure, and manage multiple plugins.
Plugin form element provides two Form API elements — plugin and plugins — that let developers embed plugin configuration forms directly inside any Drupal form.
The plugin element renders the configuration form for a single pre-selected plugin (e.g. one condition, one action). The plugins element provides a full multi-item UI backed by vertical tabs, where users can add, configure, and remove multiple plugins from any plugin manager — with optional cardinality limits and allowlists.
Features
#type => 'plugin'— renders the configuration form for a single plugin instance#type => 'plugins'— multi-item UI with vertical tabs, AJAX add/remove, and form submission handling- Works with any plugin manager implementing
PluginManagerInterface - Supports
FilteredPluginManagerInterfacefor context-aware plugin filtering #cardinalityproperty to limit how many plugins can be added#allowed_pluginsproperty to restrict which plugins appear in the Add menu- Full compatibility with
PluginFormInterfaceandPluginWithFormsInterface
Usage
Configure a single plugin whose ID you already know:
$form['condition'] = [
'#type' => 'plugin',
'#title' => $this->t('Condition'),
'#plugin_manager' => 'plugin.manager.condition',
'#default_value' => [
'id' => 'language',
'langcodes' => ['en' => 'en'],
],
];Let users pick and configure multiple plugins from any manager:
$form['conditions'] = [
'#type' => 'plugins',
'#title' => $this->t('Conditions'),
'#plugin_manager' => 'plugin.manager.condition',
'#cardinality' => -1, // -1 = unlimited
'#allowed_plugins' => ['language', 'request_path'], // optional allowlist
'#default_value' => $saved_config, // keyed by UUID
];On submit, $form_state->getValue('conditions') returns a UUID-keyed array of plugin configurations — ready to store and reinstantiate.
Depends on
Dependencies of the latest stable release
No dependencies recorded for this project.
Required by
Tracked projects that depend on this one
No tracked projects depend on this one yet.