public function DisplayLink::render in Drupal 9
Same name and namespace in other branches
- 8 core/modules/views/src/Plugin/views/area/DisplayLink.php \Drupal\views\Plugin\views\area\DisplayLink::render()
Render the area.
Parameters
bool $empty: (optional) Indicator if view result is empty or not. Defaults to FALSE.
Return value
array In any case we need a valid Drupal render array to return.
Overrides AreaPluginBase::render
File
- core/
modules/ views/ src/ Plugin/ views/ area/ DisplayLink.php, line 158
Class
- DisplayLink
- Views area display_link handler.
Namespace
Drupal\views\Plugin\views\areaCode
public function render($empty = FALSE) {
if ($empty && empty($this->options['empty']) || empty($this->options['display_id'])) {
return [];
}
if (!$this
->isPathBasedDisplay($this->options['display_id'])) {
return [];
}
// Get query parameters from the exposed input and pager.
$query = $this->view
->getExposedInput();
if ($current_page = $this->view
->getCurrentPage()) {
$query['page'] = $current_page;
}
// @todo Remove this parsing once these are removed from the request in
// https://www.drupal.org/node/2504709.
foreach ([
'view_name',
'view_display_id',
'view_args',
'view_path',
'view_dom_id',
'pager_element',
'view_base_path',
AjaxResponseSubscriber::AJAX_REQUEST_PARAMETER,
FormBuilderInterface::AJAX_FORM_REQUEST,
MainContentViewSubscriber::WRAPPER_FORMAT,
] as $key) {
unset($query[$key]);
}
// Set default classes.
$classes = [
'views-display-link',
'views-display-link-' . $this->options['display_id'],
];
if ($this->options['display_id'] === $this->view->current_display) {
$classes[] = 'is-active';
}
return [
'#type' => 'link',
'#title' => $this->options['label'],
'#url' => $this->view
->getUrl($this->view->args, $this->options['display_id'])
->setOptions([
'query' => $query,
]),
'#options' => [
'view' => $this->view,
'target_display_id' => $this->options['display_id'],
'attributes' => [
'class' => $classes,
],
],
];
}