class CommentPermissions in Comment Permissions 8
Provide dynamic permissions for comments of different types.
Hierarchy
- class \Drupal\comment_perm\CommentPermissions uses StringTranslationTrait
Expanded class hierarchy of CommentPermissions
File
- src/
CommentPermissions.php, line 11
Namespace
Drupal\comment_permView source
class CommentPermissions {
use StringTranslationTrait;
/**
* Returns an array of comment type permissions.
*
* @return array
* The comment type permissions
* @see \Drupal\user\PermissionHandlerInterface::getPermissions()
*/
public function commentTypePermissions() {
$perm = array();
// Generate comment permissions for all comment types.
foreach (CommentType::loadMultiple() as $type) {
$perm += $this
->buildPermissions($type);
}
return $perm;
}
/**
* Returns a list of node permissions for a given node type.
*
* @param \Drupal\comment\Entity\CommentType $type
* The comment type.
*
* @return array
* An associative array of permission names and descriptions.
*/
protected function buildPermissions(CommentType $type) {
$type_id = $type
->id();
$type_params = array(
'%type_name' => $type
->label(),
);
return array(
"administer {$type_id} comments" => array(
'title' => $this
->t('%type_name: Administer comments and comment settings', $type_params),
),
"administer {$type_id} comment type" => array(
'title' => $this
->t('%type_name: Administer comment type and settings', $type_params),
'restrict access' => TRUE,
),
"access {$type_id} comments" => array(
'title' => $this
->t('%type_name: View comments', $type_params),
),
"post {$type_id} comments" => array(
'title' => $this
->t('%type_name: Post comments', $type_params),
),
"skip {$type_id} comment approval" => array(
'title' => $this
->t('%type_name: Skip comment approval', $type_params),
),
"edit {$type_id} own comments" => array(
'title' => $this
->t('%type_name: Edit own comments', $type_params),
),
);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CommentPermissions:: |
protected | function | Returns a list of node permissions for a given node type. | |
CommentPermissions:: |
public | function | Returns an array of comment type permissions. | |
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. |