buildLinks example

public function renderLinks($comment_entity_id$view_mode$langcode$is_in_preview) {
    $links = [
      '#theme' => 'links__comment',
      '#pre_render' => [[Link::class, 'preRenderLinks']],
      '#attributes' => ['class' => ['links', 'inline']],
    ];

    if (!$is_in_preview) {
      /** @var \Drupal\comment\CommentInterface $entity */
      $entity = $this->entityTypeManager->getStorage('comment')->load($comment_entity_id);
      if ($commented_entity = $entity->getCommentedEntity()) {
        $links['comment'] = $this->buildLinks($entity$commented_entity);
      }

      // Allow other modules to alter the comment links.       $hook_context = [
        'view_mode' => $view_mode,
        'langcode' => $langcode,
        'commented_entity' => $commented_entity,
      ];
      $this->moduleHandler->alter('comment_links', $links$entity$hook_context);
    }
    return $links;
  }
$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;
  }

  
Home | Imprint | This part of the site doesn't use cookies.