function NodeViewBuilder::renderLinks
Same name in other branches
- 9 core/modules/node/src/NodeViewBuilder.php \Drupal\node\NodeViewBuilder::renderLinks()
- 8.9.x core/modules/node/src/NodeViewBuilder.php \Drupal\node\NodeViewBuilder::renderLinks()
- 10 core/modules/node/src/NodeViewBuilder.php \Drupal\node\NodeViewBuilder::renderLinks()
#lazy_builder callback; builds a node's links.
Parameters
string $node_entity_id: The node entity ID.
string $view_mode: The view mode in which the node entity is being viewed.
string $langcode: The language in which the node entity is being viewed.
bool $is_in_preview: Whether the node is currently being previewed.
$revision_id: (optional) The identifier of the node revision to be loaded. If none is provided, the default revision will be loaded.
Return value
array A renderable array representing the node links.
File
-
core/
modules/ node/ src/ NodeViewBuilder.php, line 89
Class
- NodeViewBuilder
- View builder handler for nodes.
Namespace
Drupal\nodeCode
public static function renderLinks($node_entity_id, $view_mode, $langcode, $is_in_preview, $revision_id = NULL) {
$links = [
'#theme' => 'links__node',
'#pre_render' => [
[
Link::class,
'preRenderLinks',
],
],
'#attributes' => [
'class' => [
'links',
'inline',
],
],
];
if (!$is_in_preview) {
$storage = \Drupal::entityTypeManager()->getStorage('node');
/** @var \Drupal\node\NodeInterface $revision */
$revision = !isset($revision_id) ? $storage->load($node_entity_id) : $storage->loadRevision($revision_id);
$entity = $revision->getTranslation($langcode);
$links['node'] = static::buildLinks($entity, $view_mode);
// Allow other modules to alter the node links.
$hook_context = [
'view_mode' => $view_mode,
'langcode' => $langcode,
];
\Drupal::moduleHandler()->alter('node_links', $links, $entity, $hook_context);
}
return $links;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.