You are here

public function AlphaPagination::getAlphabet in Views Alpha Pagination 7.2

Retrieves alphabet characters, based on langcode.

Note: Do not use range(); always be explicit when defining an alphabet. This is necessary as you cannot rely on the server language to construct proper alphabet 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 alphabet characters, based on langcode.

See also

hook_alpha_pagination_alphabet_alter()

1 call to AlphaPagination::getAlphabet()
AlphaPagination::getCharacters in src/AlphaPagination.php
Retrieves the characters used to populate the pagination item list.

File

src/AlphaPagination.php, line 167

Class

AlphaPagination
A base views handler for alpha pagination.

Code

public function getAlphabet($langcode = NULL) {
  global $language;

  // Default (English).
  static $default = [
    'A',
    'B',
    'C',
    'D',
    'E',
    'F',
    'G',
    'H',
    'I',
    'J',
    'K',
    'L',
    'M',
    'N',
    'O',
    'P',
    'Q',
    'R',
    'S',
    'T',
    'U',
    'V',
    'W',
    'X',
    'Y',
    'Z',
  ];
  static $alphabets;

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

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

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

      // Arabic.
      $alphabets['ar'] = [
        'ا',
        'ب',
        'ت',
        'ث',
        'ج',
        'ح',
        'خ',
        'د',
        'ذ',
        'ر',
        'ز',
        'س',
        'ش',
        'ص',
        'ض',
        'ط',
        'ظ',
        'ع',
        'غ',
        'ف',
        'ق',
        'ك',
        'ل',
        'م',
        'ن',
        'و',
        'ه',
        'ي',
      ];

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

      // Русский (Russian).
      $alphabets['ru'] = [
        'А',
        'Б',
        'В',
        'Г',
        'Д',
        'Е',
        'Ё',
        'Ж',
        'З',
        'И',
        'Й',
        'К',
        'Л',
        'М',
        'Н',
        'О',
        'П',
        'Р',
        'С',
        'Т',
        'У',
        'Ф',
        'Х',
        'Ц',
        'Ч',
        'Ш',
        'Щ',
        'Ы',
        'Э',
        'Ю',
        'Я',
      ];

      // Allow modules and themes to alter alphabets.
      drupal_alter('alpha_pagination_alphabet', $alphabets, $this);

      // Cache the alphabets.
      cache_set($cid, $alphabets);
    }
  }

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