function Node::renderLink

Same name in other branches
  1. 9 core/modules/node/src/Plugin/views/field/Node.php \Drupal\node\Plugin\views\field\Node::renderLink()
  2. 8.9.x core/modules/node/src/Plugin/views/field/Node.php \Drupal\node\Plugin\views\field\Node::renderLink()
  3. 11.x core/modules/node/src/Plugin/views/field/Node.php \Drupal\node\Plugin\views\field\Node::renderLink()

Prepares link to the node.

Parameters

string $data: The XSS safe string for the link text.

\Drupal\views\ResultRow $values: The values retrieved from a single row of a view's query result.

Return value

string Returns a string for the link text.

2 calls to Node::renderLink()
HistoryUserTimestamp::render in core/modules/history/src/Plugin/views/field/HistoryUserTimestamp.php
Renders the field.
Node::render in core/modules/node/src/Plugin/views/field/Node.php
Renders the field.

File

core/modules/node/src/Plugin/views/field/Node.php, line 71

Class

Node
Field handler to provide simple renderer that allows linking to a node.

Namespace

Drupal\node\Plugin\views\field

Code

protected function renderLink($data, ResultRow $values) {
    if (!empty($this->options['link_to_node']) && !empty($this->additional_fields['nid'])) {
        if ($data !== NULL && $data !== '') {
            $this->options['alter']['make_link'] = TRUE;
            $this->options['alter']['url'] = Url::fromRoute('entity.node.canonical', [
                'node' => $this->getValue($values, 'nid'),
            ]);
            if (isset($this->aliases['langcode'])) {
                $languages = \Drupal::languageManager()->getLanguages();
                $langcode = $this->getValue($values, 'langcode');
                if (isset($languages[$langcode])) {
                    $this->options['alter']['language'] = $languages[$langcode];
                }
                else {
                    unset($this->options['alter']['language']);
                }
            }
        }
        else {
            $this->options['alter']['make_link'] = FALSE;
        }
    }
    return $data;
}

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