public function AdvancedPluginSelectorBase::buildSelectorForm in Plugin 8.2
Builds the selector form.
Parameters
mixed[] $form: Any suggested form elements to build upon. May be ignored.
\Drupal\Core\Form\FormStateInterface $form_state: The form state for $form and the return value. This often is not the complete (global) form state.
Return value
mixed[] The form structure.
Throws
\RuntimeException Thrown if the plugin type was not set using self::setSelectablePluginType().
Overrides PluginSelectorBase::buildSelectorForm
1 call to AdvancedPluginSelectorBase::buildSelectorForm()
- Radios::buildSelectorForm in src/
Plugin/ Plugin/ PluginSelector/ Radios.php - Builds the selector form.
1 method overrides AdvancedPluginSelectorBase::buildSelectorForm()
- Radios::buildSelectorForm in src/
Plugin/ Plugin/ PluginSelector/ Radios.php - Builds the selector form.
File
- src/
Plugin/ Plugin/ PluginSelector/ AdvancedPluginSelectorBase.php, line 61
Class
- AdvancedPluginSelectorBase
- Provides a default base for most plugin selectors.
Namespace
Drupal\plugin\Plugin\Plugin\PluginSelectorCode
public function buildSelectorForm(array $form, FormStateInterface $form_state) {
$form = parent::buildSelectorForm($form, $form_state);
$available_plugins = [];
$cacheability_metadata = CacheableMetadata::createFromRenderArray($form);
foreach (array_keys($this->selectablePluginDiscovery
->getDefinitions()) as $plugin_id) {
$available_plugin = $this->selectablePluginFactory
->createInstance($plugin_id);
if ($available_plugin instanceof PluginInspectionInterface) {
$available_plugins[] = $available_plugin;
$cacheability_metadata = $cacheability_metadata
->merge(CacheableMetadata::createFromObject($available_plugin));
}
}
$cacheability_metadata
->applyTo($form);
$plugin_selector_form_state_key = static::setPluginSelector($form_state, $this);
$form['container'] = [
'#attributes' => [
'class' => [
'plugin-selector-' . Html::getClass($this
->getPluginId()),
],
],
'#available_plugins' => $available_plugins,
'#plugin_selector_form_state_key' => $plugin_selector_form_state_key,
'#process' => [
[
get_class(),
'processBuildSelectorForm',
],
],
'#tree' => TRUE,
'#type' => 'container',
];
return $form;
}