You are here

public function DefaultSelection::validateConfigurationForm in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php \Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection::validateConfigurationForm()

Form validation handler.

Parameters

array $form: An associative array containing the structure of the plugin form as built by static::buildConfigurationForm().

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

Overrides SelectionPluginBase::validateConfigurationForm

File

core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php, line 310

Class

DefaultSelection
Default plugin implementation of the Entity Reference Selection plugin.

Namespace

Drupal\Core\Entity\Plugin\EntityReferenceSelection

Code

public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
  parent::validateConfigurationForm($form, $form_state);

  // If no checkboxes were checked for 'target_bundles', store NULL ("all
  // bundles are referenceable") rather than empty array ("no bundle is
  // referenceable" - typically happens when all referenceable bundles have
  // been deleted).
  if ($form_state
    ->getValue([
    'settings',
    'handler_settings',
    'target_bundles',
  ]) === []) {
    $form_state
      ->setValue([
      'settings',
      'handler_settings',
      'target_bundles',
    ], NULL);
  }

  // Don't store the 'target_bundles_update' button value into the field
  // config settings.
  $form_state
    ->unsetValue([
    'settings',
    'handler_settings',
    'target_bundles_update',
  ]);
}