You are here

public static function EntityReferenceBrowserWidget::validateSettingsForm in Entity Browser 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Field/FieldWidget/EntityReferenceBrowserWidget.php \Drupal\entity_browser\Plugin\Field\FieldWidget\EntityReferenceBrowserWidget::validateSettingsForm()

Validate the settings form.

File

src/Plugin/Field/FieldWidget/EntityReferenceBrowserWidget.php, line 276

Class

EntityReferenceBrowserWidget
Plugin implementation of the 'entity_reference' widget for entity browser.

Namespace

Drupal\entity_browser\Plugin\Field\FieldWidget

Code

public static function validateSettingsForm($element, FormStateInterface $form_state, $form) {
  $values = NestedArray::getValue($form_state
    ->getValues(), $element['#parents']);
  if ($values['selection_mode'] == 'selection_edit') {

    /** @var \Drupal\entity_browser\Entity\EntityBrowser $entity_browser */
    $entity_browser = EntityBrowser::load($values['entity_browser']);
    if ($entity_browser
      ->getSelectionDisplay()
      ->supportsPreselection() === FALSE) {
      $tparams = [
        '%selection_mode' => EntityBrowserElement::getSelectionModeOptions()[EntityBrowserElement::SELECTION_MODE_EDIT],
        '@browser_link' => $entity_browser
          ->toLink($entity_browser
          ->label(), 'edit-form')
          ->toString(),
      ];
      $form_state
        ->setError($element['entity_browser']);
      $form_state
        ->setError($element['selection_mode'], t('The selection mode %selection_mode requires an entity browser with a selection display plugin that supports preselection.  Either change the selection mode or update the @browser_link entity browser to use a selection display plugin that supports preselection.', $tparams));
    }
  }
}