function Links::getLinks

Same name and namespace in other branches
  1. 8.9.x core/modules/views/src/Plugin/views/field/Links.php \Drupal\views\Plugin\views\field\Links::getLinks()
  2. 10 core/modules/views/src/Plugin/views/field/Links.php \Drupal\views\Plugin\views\field\Links::getLinks()
  3. 11.x core/modules/views/src/Plugin/views/field/Links.php \Drupal\views\Plugin\views\field\Links::getLinks()

Gets the list of links used by this field.

Return value

array The links which are used by the render function.

1 call to Links::getLinks()
Dropbutton::render in core/modules/views/src/Plugin/views/field/Dropbutton.php
Renders the field.

File

core/modules/views/src/Plugin/views/field/Links.php, line 63

Class

Links
An abstract handler which provides a collection of links.

Namespace

Drupal\views\Plugin\views\field

Code

protected function getLinks() {
    $links = [];
    foreach ($this->options['fields'] as $field) {
        if (empty($this->view->field[$field]->last_render_text)) {
            continue;
        }
        $title = $this->view->field[$field]->last_render_text;
        $path = '';
        $url = NULL;
        if (!empty($this->view->field[$field]->options['alter']['path'])) {
            $path = $this->view->field[$field]->options['alter']['path'];
        }
        elseif (!empty($this->view->field[$field]->options['alter']['url']) && $this->view->field[$field]->options['alter']['url'] instanceof UrlObject) {
            $url = $this->view->field[$field]->options['alter']['url'];
        }
        // Make sure that tokens are replaced for this paths as well.
        $tokens = $this->getRenderTokens([]);
        $path = strip_tags(Html::decodeEntities($this->viewsTokenReplace($path, $tokens)));
        $links[$field] = [
            'url' => $path ? UrlObject::fromUri('internal:/' . $path) : $url,
            'title' => $title,
        ];
        if (!empty($this->options['destination'])) {
            $links[$field]['query'] = \Drupal::destination()->getAsArray();
        }
    }
    return $links;
}

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