public function AlphaPagination::getEntityPrefixes in Views Alpha Pagination 7.2
Retrieve the distinct first character prefix from the field tables.
Mark them as TRUE so their pagination item is represented properly.
Note that the node title is a special case that we have to take from the node table as opposed to the body or any custom fields.
@todo This should be cleaned up more and fixed "properly".
Return value
array An indexed array containing a unique array of entity prefixes.
1 call to AlphaPagination::getEntityPrefixes()
- AlphaPagination::getCharacters in src/
AlphaPagination.php - Retrieves the characters used to populate the pagination item list.
File
- src/
AlphaPagination.php, line 449
Class
- AlphaPagination
- A base views handler for alpha pagination.
Code
public function getEntityPrefixes() {
$prefixes = [];
if ($entity_ids = $this
->getEntityIds()) {
switch ($this
->getOption('paginate_view_field')) {
case 'name':
$table = $this->handler->view->base_table;
$where = $this->handler->view->base_field;
// Extract the "name" field from the entity property info.
$table_data = views_fetch_data($table);
$entity_info = entity_get_property_info($table_data['table']['entity type']);
$field = isset($entity_info['properties']['name']['schema field']) ? $entity_info['properties']['name']['schema field'] : 'name';
break;
case 'title':
$table = $this->handler->view->base_table;
$where = $this->handler->view->base_field;
// Extract the "title" field from the entity property info.
$table_data = views_fetch_data($table);
$entity_info = entity_get_property_info($table_data['table']['entity type']);
$field = isset($entity_info['properties']['title']['schema field']) ? $entity_info['properties']['title']['schema field'] : 'title';
break;
default:
if (strpos($this
->getOption('paginate_view_field'), ':') === FALSE) {
// Format field name and table for single value fields
$field = $this
->getOption('paginate_view_field') . '_value';
$table = 'field_data_' . $this
->getOption('paginate_view_field');
}
else {
// Format field name and table for compound value fields
$field = str_replace(':', '_', $this
->getOption('paginate_view_field'));
$field_name_components = explode(':', $this
->getOption('paginate_view_field'));
$table = 'field_data_' . $field_name_components[0];
}
$where = 'entity_id';
break;
}
$result = db_query('SELECT DISTINCT(SUBSTR(' . $field . ', 1, 1)) AS prefix
FROM {' . $table . '}
WHERE ' . $where . ' IN ( :nids )', [
':nids' => $entity_ids,
]);
while ($data = $result
->fetchObject()) {
$prefixes[] = is_numeric($data->prefix) ? $data->prefix : drupal_strtoupper($data->prefix);
}
}
return array_unique(array_filter($prefixes));
}