NodeViewBuilder::buildLinks

protected static NodeViewBuilder::buildLinks(NodeInterface $entity, $view_mode)

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().

File

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

Class

NodeViewBuilder
View builder handler 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')),
  );
}
doc_Drupal
2016-10-29 09:31:48
Comments
Leave a Comment

Please login to continue.