protected function AdvancedPluginSelectorBase::buildSelector in Plugin 8.2
Builds the form elements for the actual plugin selector.
Parameters
array $root_element: The plugin's root element.
\Drupal\Core\Form\FormStateInterface $form_state: The form's state.
\Drupal\Component\Plugin\PluginInspectionInterface[] $plugins: The available plugins.
Return value
array The selector's form elements.
3 calls to AdvancedPluginSelectorBase::buildSelector()
- AdvancedPluginSelectorBase::buildMultipleAvailablePlugins in src/
Plugin/ Plugin/ PluginSelector/ AdvancedPluginSelectorBase.php - Builds the form elements for multiple plugins.
- Radios::buildSelector in src/
Plugin/ Plugin/ PluginSelector/ Radios.php - Builds the form elements for the actual plugin selector.
- SelectList::buildSelector in src/
Plugin/ Plugin/ PluginSelector/ SelectList.php - Builds the form elements for the actual plugin selector.
2 methods override AdvancedPluginSelectorBase::buildSelector()
- Radios::buildSelector in src/
Plugin/ Plugin/ PluginSelector/ Radios.php - Builds the form elements for the actual plugin selector.
- SelectList::buildSelector in src/
Plugin/ Plugin/ PluginSelector/ SelectList.php - Builds the form elements for the actual plugin selector.
File
- src/
Plugin/ Plugin/ PluginSelector/ AdvancedPluginSelectorBase.php, line 301
Class
- AdvancedPluginSelectorBase
- Provides a default base for most plugin selectors.
Namespace
Drupal\plugin\Plugin\Plugin\PluginSelectorCode
protected function buildSelector(array $root_element, FormStateInterface $form_state, array $plugins) {
$build['container'] = [
'#attributes' => [
'class' => [
'plugin-selector-' . Html::getClass($this
->getPluginId() . '-selector'),
],
],
'#type' => 'container',
];
$build['container']['plugin_id'] = [
'#markup' => 'This element must be overridden to provide the plugin ID.',
];
$root_element_parents = $root_element['#parents'];
// Compute the button's name based on its position in the form, but we
// cannot use "][" to indicate nesting as we would usually do, because then
// \Drupal\Core\Form\FormBuilder::buttonWasClicked() cannot recognize the
// button when it is clicked.
$change_button_name_parts = array_merge($root_element_parents, [
'select',
'container',
'change',
]);
$change_button_name = implode('__', $change_button_name_parts);
$build['container']['change'] = [
'#ajax' => [
'callback' => [
get_class(),
'ajaxRebuildForm',
],
],
'#attributes' => [
'class' => [
'js-hide',
],
],
'#limit_validation_errors' => [
array_merge($root_element['#parents'], [
'select',
'plugin_id',
]),
],
'#name' => $change_button_name,
'#submit' => array(
array(
get_class(),
'rebuildForm',
),
),
'#type' => 'submit',
'#value' => $this
->t('Choose'),
];
return $build;
}