You are here

function _lexicon_alphabar in Lexicon 7

Same name and namespace in other branches
  1. 6 lexicon.module \_lexicon_alphabar()

Function that builds up the alphabar that is displayed at the top of the Lexicon overview page.

1 call to _lexicon_alphabar()
_lexicon_overview in includes/lexicon.pages.inc
Lexicon overview function that creates all the data end renders the output through the various theme templates.

File

includes/lexicon.pages.inc, line 235
Page callbacks for the Lexicon module

Code

function _lexicon_alphabar($vid, &$tree) {
  $path = variable_get('lexicon_path_' . $vid, 'lexicon/' . $vid);
  $page_per_letter = variable_get('lexicon_page_per_letter', FALSE);
  if (variable_get('lexicon_suppress_unused', FALSE)) {

    // Just make it empty; it will be filled in below.
    $letters = array();
  }
  else {

    // Create the array of characters to use for the alphabar.
    $lets = array_merge(variable_get('lexicon_alphabet', range('a', 'z')), variable_get('lexicon_digits', range('0', '9')));
    $letters = drupal_map_assoc($lets);
  }

  // For each term in the vocabulary get the first letter and put it in the
  // array with the correct link.
  foreach ($tree as $key => $term) {

    // If terms should not be marked if a term has no description continue with
    // the next term.
    if (!variable_get('lexicon_allow_no_description', FALSE) && empty($term->description)) {
      continue;
    }
    $term->let = drupal_strtolower(drupal_substr($term->name, 0, 1));

    // If the Lexicon is split up in separate pages per letter the link must
    // refer to the appropriate page.
    if ($page_per_letter) {
      $letters[$term->let] = l($term->let, $path . '/letter_' . $term->let, array(
        'attributes' => array(
          'class' => array(
            'lexicon-item',
          ),
        ),
      ));
    }
    else {
      $letters[$term->let] = l($term->let, $path, array(
        'fragment' => 'letter_' . $term->let,
        'attributes' => array(
          'class' => array(
            'lexicon-item',
          ),
        ),
      ));
    }
  }
  $lexicon_alphabar = new stdClass();
  $lexicon_alphabar->separator = ' ' . variable_get('lexicon_alphabar_separator', '|') . ' ';
  $lexicon_alphabar->instructions = check_plain(variable_get('lexicon_alphabar_instruction', _lexicon_alphabar_instruction_default()));
  $lexicon_alphabar->letters = $letters;
  return theme('lexicon_alphabar', array(
    'lexicon_alphabar' => $lexicon_alphabar,
  ));
}