public function ViewsSelection::settingsFormValidate

Element validate; Check View is valid.

File

drupal/core/modules/views/lib/Drupal/views/Plugin/entity_reference/selection/ViewsSelection.php, line 202
Contains \Drupal\views\Plugin\entity_reference\selection\ViewsSelection.

Class

ViewsSelection
Plugin implementation of the 'selection' entity_reference.

Namespace

Drupal\views\Plugin\entity_reference\selection

Code

public function settingsFormValidate($element, &$form_state, $form) {

  // Split view name and display name from the 'view_and_display' value.
  if (!empty($element['view_and_display']['#value'])) {
    list($view, $display) = explode(':', $element['view_and_display']['#value']);
  }
  else {
    form_error($element, t('The views entity selection mode requires a view.'));
    return;
  }

  // Explode the 'arguments' string into an actual array. Beware, explode()
  // turns an empty string into an array with one empty string. We'll need an
  // empty array instead.
  $arguments_string = trim($element['arguments']['#value']);
  if ($arguments_string === '') {
    $arguments = array();
  }
  else {

    // array_map() is called to trim whitespaces from the arguments.
    $arguments = array_map('trim', explode(',', $arguments_string));
  }
  $value = array(
    'view_name' => $view,
    'display_name' => $display,
    'arguments' => $arguments,
  );
  form_set_value($element, $value, $form_state);
}