You are here

protected static function NodeViewBuilder::buildLinks in Zircon Profile 8.0

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 120
Contains \Drupal\node\NodeViewBuilder.

Class

NodeViewBuilder
Render controller for nodes.

Namespace

Drupal\node

Code

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

  // 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'] = array(
      'title' => t('Read more<span class="visually-hidden"> about @title</span>', array(
        '@title' => $node_title_stripped,
      )),
      'url' => $entity
        ->urlInfo(),
      'language' => $entity
        ->language(),
      'attributes' => array(
        'rel' => 'tag',
        'title' => $node_title_stripped,
      ),
    );
  }
  return array(
    '#theme' => 'links__node__node',
    '#links' => $links,
    '#attributes' => array(
      'class' => array(
        'links',
        'inline',
      ),
    ),
  );
}