protected function CommentLazyBuilders::buildLinks in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/comment/src/CommentLazyBuilders.php \Drupal\comment\CommentLazyBuilders::buildLinks()
Build the default links (reply, edit, delete …) for a comment.
Parameters
\Drupal\comment\CommentInterface $entity: The comment object.
\Drupal\Core\Entity\EntityInterface $commented_entity: The entity to which the comment is attached.
Return value
array An array that can be processed by drupal_pre_render_links().
1 call to CommentLazyBuilders::buildLinks()
- CommentLazyBuilders::renderLinks in core/
modules/ comment/ src/ CommentLazyBuilders.php - #lazy_builder callback; builds a comment's links.
File
- core/
modules/ comment/ src/ CommentLazyBuilders.php, line 169 - Contains \Drupal\comment\CommentLazyBuilders.
Class
- CommentLazyBuilders
- Defines a service for comment #lazy_builder callbacks.
Namespace
Drupal\commentCode
protected function buildLinks(CommentInterface $entity, EntityInterface $commented_entity) {
$links = array();
$status = $commented_entity
->get($entity
->getFieldName())->status;
if ($status == CommentItemInterface::OPEN) {
if ($entity
->access('delete')) {
$links['comment-delete'] = array(
'title' => t('Delete'),
'url' => $entity
->urlInfo('delete-form'),
);
}
if ($entity
->access('update')) {
$links['comment-edit'] = array(
'title' => t('Edit'),
'url' => $entity
->urlInfo('edit-form'),
);
}
if ($entity
->access('create')) {
$links['comment-reply'] = array(
'title' => t('Reply'),
'url' => Url::fromRoute('comment.reply', [
'entity_type' => $entity
->getCommentedEntityTypeId(),
'entity' => $entity
->getCommentedEntityId(),
'field_name' => $entity
->getFieldName(),
'pid' => $entity
->id(),
]),
);
}
if (!$entity
->isPublished() && $entity
->access('approve')) {
$links['comment-approve'] = array(
'title' => t('Approve'),
'url' => Url::fromRoute('comment.approve', [
'comment' => $entity
->id(),
]),
);
}
if (empty($links) && $this->currentUser
->isAnonymous()) {
$links['comment-forbidden']['title'] = $this->commentManager
->forbiddenMessage($commented_entity, $entity
->getFieldName());
}
}
// Add translations link for translation-enabled comment bundles.
if ($this->moduleHandler
->moduleExists('content_translation') && $this
->access($entity)
->isAllowed()) {
$links['comment-translations'] = array(
'title' => t('Translate'),
'url' => $entity
->urlInfo('drupal:content-translation-overview'),
);
}
return array(
'#theme' => 'links__comment__comment',
// The "entity" property is specified to be present, so no need to check.
'#links' => $links,
'#attributes' => array(
'class' => array(
'links',
'inline',
),
),
);
}