public function AlphaPaginationGroup::render in Views Alpha Pagination 8.2
Renders the field.
Parameters
\Drupal\views\ResultRow $values: The values retrieved from a single row of a view's query result.
Return value
string|\Drupal\Component\Render\MarkupInterface The rendered output. If the output is safe it will be wrapped in an object that implements MarkupInterface. If it is empty or unsafe it will be a string.
Overrides FieldPluginBase::render
File
- src/
Plugin/ views/ field/ AlphaPaginationGroup.php, line 108
Class
- AlphaPaginationGroup
- A handler to provide a field that generates alpha pagination values.
Namespace
Drupal\alpha_pagination\Plugin\views\fieldCode
public function render(ResultRow $values) {
$areas = $this->alphaPagination
->getAreaHandlers();
// Immediately return if there is no handler.
if (!$areas) {
return '';
}
$this->alphaPagination
->setHandler($areas[0]);
$path = $this->alphaPagination
->getOption('paginate_link_path');
list($entityType, $field_name) = explode('__', $this->alphaPagination
->getOption('paginate_view_field'), 2);
if (!isset($this->view->field[$field_name])) {
return '';
}
/** @var Drupal\views\Plugin\views\field\FieldPluginBase $field */
$field = $this->view->field[$field_name];
// Render field if it hasn't already.
if (empty($field->last_render)) {
$field
->renderText($values);
}
// Return just the first character of the value.
$value = $this->alphaPagination
->getValue(!empty($field->last_render) ? Unicode::ucfirst(substr(strip_tags($field->last_render), 0, 1)) : '');
$label = $this->alphaPagination
->getLabel($value);
// Prepend an anchor if the link path starts with #. Using the "link"
// element will cause an empty href attribute to be printed. This can cause
// issues with certain JavaScript or CSS styling that targets if that
// attribute is simply present, regardless if it's empty. To avoid that,
// use the "html_tag" type so only the name attribute is printed.
if ($value && $path && $path[0] === '#') {
$name = $this->token
->replace(substr($path, 1), $this->alphaPagination
->getTokens($value));
$label = [
'#type' => 'html_tag',
'#theme' => 'html_tag__alpha_pagination__anchor',
'#tag' => 'a',
'#value' => '',
'#attributes' => [
'name' => $name,
],
'#suffix' => $label,
];
}
return $label;
}