class CommentManager in Comment Permissions 8
Overrides CommentManager service class.
Hierarchy
- class \Drupal\comment\CommentManager implements CommentManagerInterface uses DeprecatedServicePropertyTrait, StringTranslationTrait
- class \Drupal\comment_perm\CommentManager
Expanded class hierarchy of CommentManager
File
- src/
CommentManager.php, line 15
Namespace
Drupal\comment_permView source
class CommentManager extends CommentManagerBase {
/**
* {@inheritdoc}
*/
public function forbiddenMessage(EntityInterface $entity, $field_name) {
if (!isset($this->authenticatedCanPostComments)) {
// We only output a link if we are certain that users will get the
// permission to post comments by logging in.
$auth_role = $this->entityTypeManager
->getStorage('user_role')
->load(RoleInterface::AUTHENTICATED_ID);
if ($auth_role
->hasPermission('post comments') || $auth_role
->hasPermission("post {$entity->bundle()} comments")) {
$this->authenticatedCanPostComments = TRUE;
}
}
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(),
];
}
if ($this->userConfig
->get('register') != UserInterface::REGISTER_ADMINISTRATORS_ONLY) {
// Users can register themselves.
return $this
->t('<a href=":login">Log in</a> or <a href=":register">register</a> to post comments', [
':login' => Url::fromRoute('user.login', [], [
'query' => $destination,
])
->toString(),
':register' => Url::fromRoute('user.register', [], [
'query' => $destination,
])
->toString(),
]);
}
else {
// Only admins can add new users, no public registration.
return $this
->t('<a href=":login">Log in</a> to post comments', [
':login' => Url::fromRoute('user.login', [], [
'query' => $destination,
])
->toString(),
]);
}
}
return '';
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CommentManager:: |
protected | property | Whether the \Drupal\user\RoleInterface::AUTHENTICATED_ID can post comments. | |
CommentManager:: |
protected | property | The current user. | |
CommentManager:: |
protected | property | ||
CommentManager:: |
protected | property | The entity display repository. | |
CommentManager:: |
protected | property | The entity field manager. | |
CommentManager:: |
protected | property | The entity type manager. | |
CommentManager:: |
protected | property | The module handler service. | |
CommentManager:: |
protected | property | The user settings config object. | |
CommentManager:: |
public | function |
Creates a comment_body field. Overrides CommentManagerInterface:: |
|
CommentManager:: |
public | function |
Provides a message if posting comments is forbidden. Overrides CommentManager:: |
|
CommentManager:: |
public | function |
Returns the number of new comments available on a given entity for a user. Overrides CommentManagerInterface:: |
|
CommentManager:: |
public | function |
Utility function to return an array of comment fields. Overrides CommentManagerInterface:: |
|
CommentManager:: |
public | function | Construct the CommentManager object. | |
CommentManagerInterface:: |
constant | Comments are displayed in a flat list - expanded. | ||
CommentManagerInterface:: |
constant | Comments are displayed as a threaded list - expanded. | ||
DeprecatedServicePropertyTrait:: |
public | function | Allows to access deprecated/removed properties. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |