You are here

public function DisplayPluginBase::validate in Views (for Drupal 7) 8.3

Make sure the display and all associated handlers are valid.

Return value

Empty array if the display is valid; an array of error strings if it is not.

Overrides PluginBase::validate

1 call to DisplayPluginBase::validate()
Page::validate in lib/Drupal/views/Plugin/views/display/Page.php
Make sure the display and all associated handlers are valid.
1 method overrides DisplayPluginBase::validate()
Page::validate in lib/Drupal/views/Plugin/views/display/Page.php
Make sure the display and all associated handlers are valid.

File

lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php, line 2558
Definition of Drupal\views\Plugin\views\display\DisplayPluginBase.

Class

DisplayPluginBase
The default display plugin handler. Display plugins handle options and basic mechanisms for different output methods.

Namespace

Drupal\views\Plugin\views\display

Code

public function validate() {
  $errors = array();

  // Make sure displays that use fields HAVE fields.
  if ($this
    ->usesFields()) {
    $fields = FALSE;
    foreach ($this
      ->getHandlers('field') as $field) {
      if (empty($field->options['exclude'])) {
        $fields = TRUE;
      }
    }
    if (!$fields) {
      $errors[] = t('Display "@display" uses fields but there are none defined for it or all are excluded.', array(
        '@display' => $this->display['display_title'],
      ));
    }
  }
  if ($this
    ->hasPath() && !$this
    ->getOption('path')) {
    $errors[] = t('Display "@display" uses a path but the path is undefined.', array(
      '@display' => $this->display['display_title'],
    ));
  }

  // Validate style plugin
  $style = $this
    ->getPlugin('style');
  if (empty($style)) {
    $errors[] = t('Display "@display" has an invalid style plugin.', array(
      '@display' => $this->display['display_title'],
    ));
  }
  else {
    $result = $style
      ->validate();
    if (!empty($result) && is_array($result)) {
      $errors = array_merge($errors, $result);
    }
  }

  // Validate query plugin.
  $query = $this
    ->getPlugin('query');
  $result = $query
    ->validate();
  if (!empty($result) && is_array($result)) {
    $errors = array_merge($errors, $result);
  }

  // Validate handlers
  foreach (ViewExecutable::viewsHandlerTypes() as $type => $info) {
    foreach ($this
      ->getHandlers($type) as $handler) {
      $result = $handler
        ->validate();
      if (!empty($result) && is_array($result)) {
        $errors = array_merge($errors, $result);
      }
    }
  }
  return $errors;
}