You are here

public function AlphaPagination::validate in Views Alpha Pagination 7.2

File

src/AlphaPagination.php, line 763

Class

AlphaPagination
A base views handler for alpha pagination.

Code

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

  // Immediately return if display doesn't have the handler in question.
  $items = $this->handler->view
    ->get_items($this->handler->handler_type, $display_id);
  $field = $this->handler->real_field ?: $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' => $this->handler->real_field,
        '@name' => $this->handler->view->name,
        '@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->name,
        '@display' => $this->handler->view->current_display,
      ]);
    }
  }
  return $errors["{$name}:{$display_id}"];
}