You are here

public static function EntityQueueForm::entityReferenceSelectionSettingsValidate in Entityqueue 8

Form element validation handler; Invokes selection plugin's validation.

Parameters

array $form: The form where the settings form is being included in.

\Drupal\Core\Form\FormStateInterface $form_state: The form state of the (entire) configuration form.

File

src/Form/EntityQueueForm.php, line 354

Class

EntityQueueForm
Base form for entity queue edit forms.

Namespace

Drupal\entityqueue\Form

Code

public static function entityReferenceSelectionSettingsValidate(array $form, FormStateInterface $form_state) {

  /** @var \Drupal\entityqueue\EntityQueueInterface $queue */
  $queue = $form_state
    ->getFormObject()
    ->getEntity();

  /** @var \Drupal\Core\Entity\EntityReferenceSelection\SelectionInterface $selection_handler */
  $selection_handler = \Drupal::service('plugin.manager.entity_reference_selection')
    ->getInstance($queue
    ->getEntitySettings());

  // @todo Take care of passing the right $form and $form_state structures to
  // the selection validation method. For now, we just have to duplicate the
  // validation of the 'default' selection plugin.
  $selection_handler
    ->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".
  if ($form_state
    ->getValue([
    'entity_settings',
    'handler_settings',
    'target_bundles',
  ]) === []) {
    $form_state
      ->setValue([
      'entity_settings',
      'handler_settings',
      'target_bundles',
    ], NULL);
  }
}