function DisplayLink::render

Same name in other branches
  1. 9 core/modules/views/src/Plugin/views/area/DisplayLink.php \Drupal\views\Plugin\views\area\DisplayLink::render()
  2. 10 core/modules/views/src/Plugin/views/area/DisplayLink.php \Drupal\views\Plugin\views\area\DisplayLink::render()
  3. 11.x core/modules/views/src/Plugin/views/area/DisplayLink.php \Drupal\views\Plugin\views\area\DisplayLink::render()

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\area

Code

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,
            ],
        ],
    ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.