protected CommentLazyBuilders::buildLinks(CommentInterface $entity, EntityInterface $commented_entity)
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().
File
- core/modules/comment/src/CommentLazyBuilders.php, line 164
Class
- CommentLazyBuilders
- Defines a service for comment #lazy_builder callbacks.
Namespace
Drupal\comment
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | 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' )), ); } |
Please login to continue.