You are here

protected function Node::renderLink in Drupal 9

Same name and namespace in other branches
  1. 8 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 69

Class

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

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