public function AdvancedPluginSelectorBase::validateSelectorForm in Plugin 8.2
Validates the selector form.
Parameters
mixed[] $form: The selector form as built by static::buildSelectorForm().
\Drupal\Core\Form\FormStateInterface $form_state: The form state for $form. This often is not the complete (global) form state.
Overrides PluginSelectorInterface::validateSelectorForm
File
- src/
Plugin/ Plugin/ PluginSelector/ AdvancedPluginSelectorBase.php, line 145
Class
- AdvancedPluginSelectorBase
- Provides a default base for most plugin selectors.
Namespace
Drupal\plugin\Plugin\Plugin\PluginSelectorCode
public function validateSelectorForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValues();
$plugin_id = NestedArray::getValue($values, array_merge($form['container']['#parents'], array(
'select',
'container',
'plugin_id',
)));
$selected_plugin = $this
->getSelectedPlugin();
if (!$selected_plugin && $plugin_id || $selected_plugin && $plugin_id != $selected_plugin
->getPluginId()) {
// Keep track of all previously selected plugins so their configuration
// does not get lost.
if (isset($this
->getPreviouslySelectedPlugins()[$plugin_id])) {
$this
->setSelectedPlugin($this
->getPreviouslySelectedPlugins()[$plugin_id]);
}
elseif ($plugin_id) {
$this
->setSelectedPlugin($this->selectablePluginFactory
->createInstance($plugin_id));
}
else {
$this
->resetSelectedPlugin();
}
// If a (different) plugin was chosen and its form must be displayed,
// rebuild the form.
if ($this
->getCollectPluginConfiguration() && $this
->getSelectedPlugin() instanceof PluginFormInterface) {
$form_state
->setRebuild();
}
}
elseif ($this
->getCollectPluginConfiguration() && $selected_plugin instanceof PluginFormInterface) {
$selected_plugin
->validateConfigurationForm($form['container']['plugin_form'], $form_state);
}
}