You are here

public function AlphaPagination::validate in Views Alpha Pagination 8.2

File

src/AlphaPagination.php, line 886

Class

AlphaPagination
A base views handler for alpha pagination.

Namespace

Drupal\alpha_pagination

Code

public function validate() {
  $name = $this->handler->view
    ->id();
  $display_id = $this->handler->view->current_display;

  // Immediately return if display doesn't have the handler in question.
  $items = $this->handler->view
    ->getHandlers($this->handler->areaType, $display_id);
  $field = $this->handler->realField ?: $this->handler->field;
  if (!isset($items[$field])) {
    return [];
  }
  static $errors = [];
  if (!isset($errors["{$name}:{$display_id}"])) {
    $errors["{$name}:{$display_id}"] = [];

    // Show an error if not found.
    $areas = $this
      ->getAreaHandlers();
    if (!$areas) {
      $errors["{$name}:{$display_id}"][] = t('The view "@name:@display" must have at least one configured alpha pagination area in either the header or footer to use "@field".', [
        '@field' => $field,
        '@name' => $this->handler->view
          ->id(),
        '@display' => $this->handler->view->current_display,
      ]);
    }
    elseif (count($areas) > 1) {
      $errors["{$name}:{$display_id}"][] = t('The view "@name:@display" can only have one configured alpha pagination area in either the header or footer.', [
        '@name' => $this->handler->view
          ->id(),
        '@display' => $this->handler->view->current_display,
      ]);
    }
  }
  return $errors["{$name}:{$display_id}"];
}