You are here

public function AlphaPagination::getNumbers in Views Alpha Pagination 8.2

Retrieves numeric characters, based on langcode.

Note: Do not use range(); always be explicit when defining numbers. This is necessary as you cannot rely on the server language to construct proper numeric characters.

Parameters

string $langcode: The langcode to return. If the langcode does not exist, it will default to English.

Return value

array An indexed array of numeric characters, based on langcode.

See also

hook_alpha_pagination_numbers_alter()

2 calls to AlphaPagination::getNumbers()
AlphaPagination::getCharacters in src/AlphaPagination.php
Retrieves the characters used to populate the pagination item list.
AlphaPagination::isNumeric in src/AlphaPagination.php
Determines if value is "numeric".

File

src/AlphaPagination.php, line 671

Class

AlphaPagination
A base views handler for alpha pagination.

Namespace

Drupal\alpha_pagination

Code

public function getNumbers($langcode = NULL) {

  // Default (English).
  static $default = [
    '0',
    '1',
    '2',
    '3',
    '4',
    '5',
    '6',
    '7',
    '8',
    '9',
  ];
  static $numbers;

  // If the langcode is not explicitly specified, default to global langcode.
  if (!isset($langcode)) {
    $langcode = $this->language;
  }

  // Retrieve numbers.
  if (!isset($numbers)) {

    // Attempt to retrieve from database cache.
    $cid = "alpha_pagination:numbers";
    if (($cache = $this->cacheBackend
      ->get($cid)) && !empty($cache->data)) {
      $numbers = $cache->data;
    }
    else {

      // English. Initially the default value, but can be modified in alter.
      $numbers['en'] = $default;

      // Allow modules and themes to alter numbers.
      $this->moduleHandler
        ->alter('alpha_pagination_numbers', $numbers, $this);

      // Cache the numbers.
      $this->cacheBackend
        ->set($cid, $numbers);
    }
  }

  // Return numbers based on langcode.
  return isset($numbers[$langcode]) ? $numbers[$langcode] : $default;
}