function alpha_pagination_handler_pagination::render in Views Alpha Pagination 7
Render the alphabetic paginator
Parameters
bool $empty: If this area should be emptym then return it as empty.
Return value
string $paginator A string representing the complete paginator including linked and unlinked options.
Overrides views_handler_area::render
File
- views/
alpha_pagination_handler_pagination.inc, line 336 - Definition of alpha_pagination_handler_pagination.
Class
- alpha_pagination_handler_pagination
- Views area handler to display an alphabetic pagination representive of the entire result set for this view and not just the limited number being displayed by the view's configuration
Code
function render($empty = FALSE) {
// Create the wrapper.
$wrapper = array(
'#theme_wrappers' => array(
'container__alpha_pagination__wrapper',
),
'#attributes' => array(),
'#attached' => array(
'library' => array(
array(
'alpha_pagination',
'alpha_pagination',
),
),
),
);
$this
->addOptionClasses('paginate_class', $wrapper['#attributes']);
// Account for an argument-less call to the page.
if (empty($this->view->args)) {
$this->view->args[0] = 'all';
}
$all_label = !empty($this->options['paginate_all_label']) ? t(check_plain($this->options['paginate_all_label'])) : t('All');
// Iterate over the alphabet and populate the items for the item list.
$items = array();
foreach ($this
->getItems() as $key => $is_link) {
$all = drupal_strtolower($key) === 'all';
$numeric = is_numeric($key);
$active = (string) $key === (string) $this->view->args[0];
$is_link = !$active && ($all || $is_link);
$label = $all ? $all_label : drupal_ucfirst($key);
// Theme link item.
if ($is_link) {
$item_data = array(
'#theme' => 'link__alpha_pagination__' . drupal_html_class($key),
'#text' => $label,
'#path' => sprintf('%s/%s', $this->options['pre_letter_path'], $key),
'#options' => array(
'attributes' => array(),
'html' => FALSE,
'query' => drupal_get_query_parameters(),
),
);
$this
->addOptionClasses('paginate_link_class', $item_data['#options']['attributes']);
}
elseif ($this->options['paginate_toggle_empty'] || $all || $active) {
$item_data = array(
'#type' => 'html_tag',
'#theme' => 'html_tag__alpha_pagination__inactive',
'#tag' => 'span',
'#value' => $label,
);
}
if (!empty($item_data)) {
// Unfortunately, the implementation of item_list in D7 core does not
// allow render arrays to be passed as data and requires premature
// rendering here.
// @todo In D8, pass the render array directly since it can process it.
$item = array(
'data' => drupal_render($item_data),
);
// Add the necessary classes for item.
if ($all) {
$this
->addOptionClasses('paginate_all_class', $item);
}
if ($numeric) {
$this
->addOptionClasses('paginate_numeric_class', $item);
}
if ($active) {
$this
->addOptionClasses('paginate_active_class', $item);
}
elseif (!$is_link) {
$this
->addOptionClasses('paginate_inactive_class', $item);
}
// Add the constructed item to the list.
$items[] = $item;
}
}
// Sanitize any classes provided for the item list.
$item_list = array(
'#theme' => 'item_list__alpha_pagination',
'#attributes' => array(),
'#items' => $items,
);
$this
->addOptionClasses('paginate_list_class', $item_list['#attributes']);
// Append the item list to the wrapper.
$wrapper[] = $item_list;
return drupal_render($wrapper);
}