// We only output a link if we are certain that users will get the
// permission to post comments by logging in.
$this->authenticatedCanPostComments =
$this->entityTypeManager
->
getStorage('user_role'
) ->
load(RoleInterface::AUTHENTICATED_ID
) ->
hasPermission('post comments'
);
} if ($this->authenticatedCanPostComments
) { // We cannot use the redirect.destination service here because these links
// sometimes appear on /node and taxonomy listing pages.
if ($entity->
get($field_name)->
getFieldDefinition()->
getSetting('form_location'
) == CommentItemInterface::FORM_SEPARATE_PAGE
) { $comment_reply_parameters =
[ 'entity_type' =>
$entity->
getEntityTypeId(),
'entity' =>
$entity->
id(),
'field_name' =>
$field_name,
];
$destination =
['destination' => Url::
fromRoute('comment.reply',
$comment_reply_parameters,
['fragment' => 'comment-form'
])->
toString()];
} else { $destination =
['destination' =>
$entity->
toUrl('canonical',
['fragment' => 'comment-form'
])->
toString()];
}