class views_handler_area_alpha_pagination in Views Alpha Pagination 7.2
Views area handler to display alphabetic pagination.
Hierarchy
- class \views_object
- class \views_handler
- class \views_handler_area
- class \views_handler
Expanded class hierarchy of views_handler_area_alpha_pagination
1 string reference to 'views_handler_area_alpha_pagination'
- alpha_pagination_views_data in ./
alpha_pagination.module - Implements hook_views_data().
File
- src/
views_handler_area_alpha_pagination.inc, line 8
View source
class views_handler_area_alpha_pagination extends \views_handler_area {
/**
* @var \AlphaPagination
*/
private $alphaPagination;
/**
* {@inheritdoc}
*/
public function construct() {
$this->alphaPagination = new AlphaPagination($this);
parent::construct();
}
/**
* {@inheritdoc}
*/
public function label() {
return '';
}
/**
* {@inheritdoc}
*/
function option_definition() {
$options = parent::option_definition();
// Global.
$options['paginate_view_field'] = [
'default' => 'title',
'translatable' => TRUE,
];
// Link.
$options['paginate_link_path'] = [
'default' => '[alpha_pagination:path]/[alpha_pagination:value]',
'translatable' => FALSE,
];
$options['paginate_link_external'] = [
'default' => 0,
'translatable' => FALSE,
];
$options['paginate_link_class'] = [
'default' => '',
'translatable' => FALSE,
];
$options['paginate_link_attributes'] = [
'default' => '',
'translatable' => FALSE,
];
// Classes.
$options['paginate_class'] = [
'default' => 'alpha-pagination',
'translatable' => FALSE,
];
$options['paginate_list_class'] = [
'default' => 'alpha-pagination-list',
'translatable' => FALSE,
];
$options['paginate_active_class'] = [
'default' => 'active',
'translatable' => FALSE,
];
$options['paginate_inactive_class'] = [
'default' => 'inactive',
'translatable' => FALSE,
];
// All.
$options['paginate_all_display'] = [
'default' => 1,
'translatable' => FALSE,
];
$options['paginate_all_class'] = [
'default' => 'all',
'translatable' => FALSE,
];
$options['paginate_all_label'] = [
'default' => t('All'),
'translatable' => TRUE,
];
$options['paginate_all_value'] = [
'default' => 'all',
'translatable' => FALSE,
];
$options['paginate_all_position'] = [
'default' => 'after',
'translatable' => FALSE,
];
$options['paginate_toggle_empty'] = [
'default' => 1,
'translatable' => FALSE,
];
// Numeric.
$options['paginate_view_numbers'] = [
'default' => 0,
'translatable' => FALSE,
];
$options['paginate_numeric_class'] = [
'default' => 'numeric',
'translatable' => FALSE,
];
$options['paginate_numeric_divider'] = [
'default' => 1,
'translatable' => FALSE,
];
$options['paginate_numeric_divider_class'] = [
'default' => 'numeric-divider',
'translatable' => FALSE,
];
$options['paginate_numeric_hide_empty'] = [
'default' => 1,
'translatable' => FALSE,
];
$options['paginate_numeric_label'] = [
'default' => '#',
'translatable' => FALSE,
];
$options['paginate_numeric_position'] = [
'default' => 'before',
'translatable' => FALSE,
];
$options['paginate_numeric_value'] = [
'default' => implode('+', $this->alphaPagination
->getNumbers()),
'translatable' => FALSE,
];
return $options;
}
/**
* {@inheritdoc}
*/
function options_submit(&$form, &$form_state) {
// Need to clear cache when options have changed.
cache_clear_all($this->alphaPagination
->getCid(), 'cache', TRUE);
// Filter attributes for any XSS vulnerabilities before saving.
if (!empty($form_state['values']['options']['paginate_link_attributes'])) {
$form_state['values']['options']['paginate_link_attributes'] = filter_xss_admin($form_state['values']['options']['paginate_link_attributes']);
}
}
/**
* {@inheritdoc}
*/
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
// Hide unnecessary label.
$form['label']['#access'] = FALSE;
// Global options.
if ($this->view->base_table == 'taxonomy_term_data') {
// Get an array list of all non-image, non-entity or other assorted reference fields.
$fields = [
'name' => 'name',
];
}
else {
// Get an array list of all non-image, non-entity or other assorted reference fields.
$fields = [
'title' => 'title',
];
}
$compound_field_types = [
'name',
];
$single_field_types = [
'text',
'text_long',
'text_with_summary',
];
$all_field_types = array_merge($single_field_types, $compound_field_types);
foreach (field_info_field_map() as $field_name => $field_definition) {
if (in_array($field_definition['type'], $all_field_types)) {
if (in_array($field_definition['type'], $compound_field_types)) {
$field_info = field_info_field($field_name);
foreach (array_keys($field_info['columns']) as $compoundFieldKey) {
$compound_field_field_name = sprintf('%s:%s', $field_name, $compoundFieldKey);
$fields[$compound_field_field_name] = $compound_field_field_name;
}
}
else {
$fields[$field_name] = $field_name;
}
}
}
$form['paginate_view_field'] = [
'#title' => t('View field to paginate against'),
'#type' => 'select',
'#options' => $fields,
'#default_value' => $this->alphaPagination
->getOption('paginate_view_field'),
'#description' => t('This will be the content field that drives the pagination.'),
];
$form['paginate_toggle_empty'] = [
'#type' => 'checkbox',
'#title' => t('Show options without results'),
'#default_value' => $this->alphaPagination
->getOption('paginate_toggle_empty'),
'#description' => t('Show or hide letters without results'),
];
// Link.
$form['paginate_link'] = [
'#type' => 'fieldset',
'#title' => t('Link'),
'#collapsible' => TRUE,
];
$form['paginate_link_path'] = [
'#title' => t('Path'),
'#type' => 'textfield',
'#size' => 60,
'#default_value' => $this->alphaPagination
->getOption('paginate_link_path'),
'#description' => t('This is the path the link will be rendered with. No beginning or ending slashes.'),
'#fieldset' => 'paginate_link',
];
$form['paginate_link_external'] = [
'#type' => 'checkbox',
'#title' => t('External'),
'#default_value' => $this->alphaPagination
->getOption('paginate_link_external'),
'#description' => t('Indicates whether this is an external link (not processed). If the above path starts with a hash symbol (#), then this option will automatically enable so it can render as a relative link to an anchor on the current page.'),
'#fieldset' => 'paginate_link',
];
$form['paginate_link_class'] = [
'#title' => t('Classes'),
'#type' => 'textfield',
'#default_value' => $this->alphaPagination
->getOption('paginate_link_class'),
'#description' => t('CSS classes for the link, separated by spaces.'),
'#fieldset' => 'paginate_link',
];
$form['paginate_link_attributes'] = [
'#type' => 'textfield',
'#title' => t('Attributes'),
'#description' => 'E.g. id|custom-id,role|navigation,data-key|value',
'#default_value' => $this->alphaPagination
->getOption('paginate_link_attributes'),
'#fieldset' => 'paginate_link',
];
$form['paginate_link_tokens'] = $this->alphaPagination
->buildTokenTree('paginate_link');
// Class options.
$form['paginate_classes'] = [
'#type' => 'fieldset',
'#title' => t('Classes'),
'#description' => t('Provide additional CSS classes on elements in the pagination; separated by spaces.'),
'#collapsible' => TRUE,
];
$form['paginate_class'] = [
'#title' => t('Wrapper'),
'#type' => 'textfield',
'#default_value' => $this->alphaPagination
->getOption('paginate_class'),
'#description' => t('The wrapper around the item list.'),
'#fieldset' => 'paginate_classes',
];
$form['paginate_list_class'] = [
'#title' => t('Item List'),
'#type' => 'textfield',
'#default_value' => $this->alphaPagination
->getOption('paginate_list_class'),
'#description' => t('The item list.'),
'#fieldset' => 'paginate_classes',
];
$form['paginate_active_class'] = [
'#title' => t('Active item'),
'#type' => 'textfield',
'#default_value' => $this->alphaPagination
->getOption('paginate_active_class'),
'#description' => t('The active list item.'),
'#fieldset' => 'paginate_classes',
];
$form['paginate_inactive_class'] = [
'#title' => t('Inactive item'),
'#type' => 'textfield',
'#default_value' => $this->alphaPagination
->getOption('paginate_inactive_class'),
'#description' => t('The inactive list item(s) that are not links, a.k.a. "no results".'),
'#fieldset' => 'paginate_classes',
];
// "All" options.
$form['paginate_all_options'] = [
'#type' => 'fieldset',
'#title' => t('"All" item'),
'#collapsible' => TRUE,
];
$form['paginate_all_display'] = [
'#type' => 'select',
'#title' => t('Display the "All" item'),
'#options' => [
0 => t('No'),
1 => t('Yes'),
],
'#default_value' => $this->alphaPagination
->getOption('paginate_all_display'),
'#description' => t('Displays the "All" link in the pagination.'),
'#fieldset' => 'paginate_all_options',
];
$form['paginate_all_position'] = [
'#type' => 'select',
'#title' => t('Position'),
'#options' => [
'before' => t('Before'),
'after' => t('After'),
],
'#default_value' => $this->alphaPagination
->getOption('paginate_all_position'),
'#description' => t('Determines where the "All" item will show up in the pagination.'),
'#dependency' => [
'edit-options-paginate-all-display' => [
1,
],
],
'#fieldset' => 'paginate_all_options',
];
$form['paginate_all_label'] = [
'#type' => 'textfield',
'#title' => t('Label'),
'#default_value' => $this->alphaPagination
->getOption('paginate_all_label'),
'#description' => t('The label to use for display the "All" item in the pagination.'),
'#dependency' => [
'edit-options-paginate-all-display' => [
1,
],
],
'#fieldset' => 'paginate_all_options',
];
$form['paginate_all_value'] = [
'#type' => 'textfield',
'#title' => t('Value'),
'#default_value' => $this->alphaPagination
->getOption('paginate_all_value'),
'#description' => t('The value to use to represent all items.'),
'#dependency' => [
'edit-options-paginate-all-display' => [
1,
],
],
'#fieldset' => 'paginate_all_options',
];
$form['paginate_all_class'] = [
'#title' => t('Classes'),
'#type' => 'textfield',
'#default_value' => $this->alphaPagination
->getOption('paginate_all_class'),
'#description' => t('CSS classes for "All" item (on <code><li></code> element); separated by spaces.'),
'#dependency' => [
'edit-options-paginate-all-display' => [
1,
],
],
'#fieldset' => 'paginate_all_options',
];
// "Numeric" options.
$form['paginate_numeric_options'] = [
'#type' => 'fieldset',
'#title' => t('Numeric items'),
'#collapsible' => TRUE,
];
$form['paginate_view_numbers'] = [
'#title' => t('Display numeric items'),
'#type' => 'select',
'#options' => [
0 => t('No'),
1 => t('Individual numbers (0-9)'),
2 => t('Single label (#)'),
],
'#default_value' => $this->alphaPagination
->getOption('paginate_view_numbers'),
'#description' => t('Displays numeric item(s) in the pagination.'),
'#fieldset' => 'paginate_numeric_options',
];
// Global numeric options.
$form['paginate_numeric_class'] = [
'#title' => t('Classes'),
'#type' => 'textfield',
'#default_value' => $this->alphaPagination
->getOption('paginate_numeric_class'),
'#description' => t('CSS classes for numeric item (on <code><li></code> element); separated by spaces.'),
'#fieldset' => 'paginate_numeric_options',
'#dependency' => [
'edit-options-paginate-view-numbers' => [
1,
2,
],
],
];
$form['paginate_numeric_position'] = [
'#type' => 'select',
'#title' => t('Position'),
'#options' => [
'before' => t('Before'),
'after' => t('After'),
],
'#default_value' => $this->alphaPagination
->getOption('paginate_numeric_position'),
'#description' => t('Determines whether numeric items are shown before or after alphabetical links in the pagination.'),
'#fieldset' => 'paginate_numeric_options',
'#dependency' => [
'edit-options-paginate-view-numbers' => [
1,
2,
],
],
];
$form['paginate_numeric_hide_empty'] = [
'#title' => t('Hide all numeric item(s) if empty'),
'#description' => t('Will not render any numeric item(s) if there are no results that start with numeric values.'),
'#type' => 'checkbox',
'#default_value' => $this->alphaPagination
->getOption('paginate_numeric_hide_empty'),
'#fieldset' => 'paginate_numeric_options',
'#dependency' => [
'edit-options-paginate-view-numbers' => [
1,
2,
],
],
];
// Individual numeric items.
$form['paginate_numeric_divider'] = [
'#type' => 'checkbox',
'#title' => t('Show divider'),
'#default_value' => $this->alphaPagination
->getOption('paginate_numeric_divider'),
'#description' => t('Will render a specific divider item before or after the numeric items have been render, based on position.'),
'#fieldset' => 'paginate_numeric_options',
'#dependency' => [
'edit-options-paginate-view-numbers' => [
1,
],
],
];
$form['paginate_numeric_divider_class'] = [
'#title' => t('Divider class'),
'#type' => 'textfield',
'#default_value' => $this->alphaPagination
->getOption('paginate_numeric_divider_class'),
'#description' => t('The class to use for the numeric divider list item.'),
'#fieldset' => 'paginate_numeric_options',
'#dependency' => [
'edit-options-paginate-view-numbers' => [
1,
],
'edit-options-paginate-numeric-divider' => [
1,
],
],
'#dependency_count' => 2,
];
// Single numeric item.
$form['paginate_numeric_label'] = [
'#title' => t('Label'),
'#type' => 'textfield',
'#default_value' => $this->alphaPagination
->getOption('paginate_numeric_label'),
'#description' => t('The label to use to represent all numeric values.'),
'#fieldset' => 'paginate_numeric_options',
'#dependency' => [
'edit-options-paginate-view-numbers' => [
2,
],
],
];
$form['paginate_numeric_value'] = [
'#title' => t('Value'),
'#type' => 'textfield',
'#default_value' => $this->alphaPagination
->getOption('paginate_numeric_value'),
'#description' => t('The value to use to represent all numeric values (i.e. URL value).'),
'#fieldset' => 'paginate_numeric_options',
'#dependency' => [
'edit-options-paginate-view-numbers' => [
2,
],
],
];
}
/**
* {@inheritdoc}
*/
function post_execute(&$values) {
$this->alphaPagination
->ensureQuery();
}
/**
* Render the alphabetic pagination.
*
* @param bool $empty
* If this area should be empty, then return it as empty.
*
* @return string
* A string representing the complete pagination including linked and
* unlinked options.
*/
function render($empty = FALSE) {
// Create the wrapper.
$wrapper = [
'#theme_wrappers' => [
'container__alpha_pagination__wrapper',
],
'#attributes' => [],
'#attached' => [
'library' => [
[
'alpha_pagination',
'alpha_pagination',
],
],
],
];
$this->alphaPagination
->addClasses($this->alphaPagination
->getOption('paginate_class'), $wrapper['#attributes']);
// Iterate over the alphabet and populate the items for the item list.
$items = [];
foreach ($this->alphaPagination
->getCharacters() as $character) {
// Add special numeric divider.
if ($character
->getValue() === '-' && $this->alphaPagination
->getOption('paginate_view_numbers') !== '2' && $this->alphaPagination
->getOption('paginate_numeric_divider')) {
// Add an empty list item.
$item = [
'data' => '',
];
$this->alphaPagination
->addClasses($this->alphaPagination
->getOption('paginate_numeric_divider_class'), $item);
$items[] = $item;
}
elseif ($build = $character
->build(TRUE)) {
$item = [
'data' => $build,
];
// Add the necessary classes for item.
if ($character
->isAll()) {
$this->alphaPagination
->addClasses($this->alphaPagination
->getOption('paginate_all_class'), $item);
}
if ($character
->isNumeric()) {
$this->alphaPagination
->addClasses($this->alphaPagination
->getOption('paginate_numeric_class'), $item);
}
if ($character
->isActive()) {
$this->alphaPagination
->addClasses($this->alphaPagination
->getOption('paginate_active_class'), $item);
}
elseif (!$character
->isEnabled()) {
$this->alphaPagination
->addClasses($this->alphaPagination
->getOption('paginate_inactive_class'), $item);
}
// Add the constructed item to the list.
$items[] = $item;
}
}
// Sanitize any classes provided for the item list.
$item_list = [
'#theme' => 'item_list__alpha_pagination',
'#attributes' => [],
'#items' => $items,
];
$this->alphaPagination
->addClasses($this->alphaPagination
->getOption('paginate_list_class'), $item_list['#attributes']);
// Append the item list to the wrapper.
$wrapper[] = $item_list;
return drupal_render($wrapper);
}
/**
* {@inheritdoc}
*/
public function ui_name($short = FALSE) {
return $this->alphaPagination
->ui_name();
}
/**
* {@inheritdoc}
*/
function validate() {
return $this->alphaPagination
->validate();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
views_handler:: |
public | property | The type of the handler, for example filter/footer/field. | |
views_handler:: |
public | property | Where the $query object will reside:. | 1 |
views_handler:: |
public | property | The actual field in the database table, maybe different on other kind of query plugins/special handlers. | |
views_handler:: |
public | property | The relationship used for this field. | |
views_handler:: |
public | property | The alias of the table of this handler which is used in the query. | |
views_handler:: |
public | property |
The top object of a view. Overrides views_object:: |
|
views_handler:: |
public | function | Take input from exposed handlers and assign to this handler, if necessary. | 1 |
views_handler:: |
public | function | Check whether current user has access to this handler. | 10 |
views_handler:: |
public | function | Determine if the handler is considered 'broken'. | 6 |
views_handler:: |
public | function | Determine if a handler can be exposed. | 2 |
views_handler:: |
public | function | Transform a string by a certain method. | |
views_handler:: |
public | function | Ensure the main table for this handler is in the query. This is used a lot. | 8 |
views_handler:: |
public | function | Render our chunk of the exposed handler form when selecting. | 1 |
views_handler:: |
public | function | Get information about the exposed form for the form renderer. | 1 |
views_handler:: |
public | function | Submit the exposed handler form. | |
views_handler:: |
public | function | Validate the exposed handler form. | 4 |
views_handler:: |
public | function | Form for exposed handler options. | 2 |
views_handler:: |
public | function | Set new exposed option defaults when exposed setting is flipped on. | 2 |
views_handler:: |
public | function | Perform any necessary changes to the form exposes prior to storage. There is no need for this function to actually store the data. | |
views_handler:: |
public | function | Validate the options form. | 1 |
views_handler:: |
public | function | Provide defaults for the handler. | |
views_handler:: |
public | function | Provide a form for setting options. | 1 |
views_handler:: |
public | function | Perform any necessary changes to the form values prior to storage. There is no need for this function to actually store the data. | |
views_handler:: |
public | function | Validate the options form. | |
views_handler:: |
public | function | Shortcut to get a handler's raw field value. | |
views_handler:: |
public | function | Get the join object that should be used for this handler. | |
views_handler:: |
public | function | Provide a form for aggregation settings. | 1 |
views_handler:: |
public | function | Perform any necessary changes to the form values prior to storage. There is no need for this function to actually store the data. | 1 |
views_handler:: |
public | function | If a handler has 'extra options' it will get a little settings widget and another form called extra_options. | 1 |
views_handler:: |
public | function | Returns TRUE if the exposed filter works like a grouped filter. | 1 |
views_handler:: |
public | function | Determine if this item is 'exposed', meaning it provides form elements to let users modify the view. | |
views_handler:: |
public | function | Define if the exposed input has to be submitted multiple times. This is TRUE when exposed filters grouped are using checkboxes as widgets. | 1 |
views_handler:: |
public | function | Determine if the argument needs a style plugin. | 1 |
views_handler:: |
public | function | Validate the options form. | 4 |
views_handler:: |
public | function | Provides a unique placeholders for handlers. | |
views_handler:: |
public | function | Run before the view is built. | 1 |
views_handler:: |
public | function | Sanitize the value for output. | |
views_handler:: |
public | function | Called just prior to query(), this lets a handler set up any relationship it needs. | |
views_handler:: |
public | function | Shortcut to display the expose/hide button. | 2 |
views_handler:: |
public | function | Shortcut to display the exposed options form. | |
views_handler:: |
public | function | If set to remember exposed input in the session, store it there. | 1 |
views_handler_area:: |
public | function |
Provide extra data to the administration form. Overrides views_handler:: |
|
views_handler_area:: |
public | function |
Init the handler with necessary data. Overrides views_handler:: |
|
views_handler_area:: |
public | function | Don't run a query. | 1 |
views_handler_area:: |
public | function |
Area handlers shouldn't have groupby. Overrides views_handler:: |
|
views_handler_area_alpha_pagination:: |
private | property | ||
views_handler_area_alpha_pagination:: |
public | function |
Views handlers use a special construct function. Overrides views_object:: |
|
views_handler_area_alpha_pagination:: |
public | function |
Overrides views_handler_area:: |
|
views_handler_area_alpha_pagination:: |
function |
Default options form that provides the label widget that all fields should
have. Overrides views_handler_area:: |
||
views_handler_area_alpha_pagination:: |
function |
Perform any necessary changes to the form values prior to storage.
There is no need for this function to actually store the data. Overrides views_handler:: |
||
views_handler_area_alpha_pagination:: |
function |
Information about options for all kinds of purposes will be held here. Overrides views_handler_area:: |
||
views_handler_area_alpha_pagination:: |
function |
Run after the view is executed, before the result is cached. Overrides views_handler:: |
||
views_handler_area_alpha_pagination:: |
function |
Render the alphabetic pagination. Overrides views_handler_area:: |
||
views_handler_area_alpha_pagination:: |
public | function |
Return a string representing this handler's name in the UI. Overrides views_handler:: |
|
views_handler_area_alpha_pagination:: |
function |
Validates the handler against the complete View. Overrides views_handler:: |
||
views_object:: |
public | property | Handler's definition. | |
views_object:: |
public | property | Except for displays, options for the object will be held here. | 1 |
views_object:: |
function | Collect this handler's option definition and alter them, ready for use. | ||
views_object:: |
public | function | Destructor. | 2 |
views_object:: |
public | function | 1 | |
views_object:: |
public | function | ||
views_object:: |
public | function | Always exports the option, regardless of the default value. | |
views_object:: |
public | function | Set default options on this object. | 1 |
views_object:: |
public | function | Set default options. | |
views_object:: |
public | function | Let the handler know what its full definition is. | |
views_object:: |
public | function | Unpack options over our existing defaults, drilling down into arrays so that defaults don't get totally blown away. | |
views_object:: |
public | function | Unpack a single option definition. | |
views_object:: |
public | function | Unpacks each handler to store translatable texts. | |
views_object:: |
public | function |