You are here

protected static function NodeViewBuilder::buildLinks in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/node/src/NodeViewBuilder.php \Drupal\node\NodeViewBuilder::buildLinks()

Build the default links (Read more) for a node.

Parameters

\Drupal\node\NodeInterface $entity: The node object.

string $view_mode: A view mode identifier.

Return value

array An array that can be processed by drupal_pre_render_links().

1 call to NodeViewBuilder::buildLinks()
NodeViewBuilder::renderLinks in core/modules/node/src/NodeViewBuilder.php
#lazy_builder callback; builds a node's links.

File

core/modules/node/src/NodeViewBuilder.php, line 124

Class

NodeViewBuilder
View builder handler for nodes.

Namespace

Drupal\node

Code

protected static function buildLinks(NodeInterface $entity, $view_mode) {
  $links = [];

  // Always display a read more link on teasers because we have no way
  // to know when a teaser view is different than a full view.
  if ($view_mode == 'teaser') {
    $node_title_stripped = strip_tags($entity
      ->label());
    $links['node-readmore'] = [
      'title' => t('Read more<span class="visually-hidden"> about @title</span>', [
        '@title' => $node_title_stripped,
      ]),
      'url' => $entity
        ->toUrl(),
      'language' => $entity
        ->language(),
      'attributes' => [
        'rel' => 'tag',
        'title' => $node_title_stripped,
      ],
    ];
  }
  return [
    '#theme' => 'links__node__node',
    '#links' => $links,
    '#attributes' => [
      'class' => [
        'links',
        'inline',
      ],
    ],
  ];
}