CommentPermissions.php in Comment Permissions 8
File
src/CommentPermissions.php
View source
<?php
namespace Drupal\comment_perm;
use Drupal\comment\Entity\CommentType;
use Drupal\Core\StringTranslation\StringTranslationTrait;
class CommentPermissions {
use StringTranslationTrait;
public function commentTypePermissions() {
$perm = array();
foreach (CommentType::loadMultiple() as $type) {
$perm += $this
->buildPermissions($type);
}
return $perm;
}
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),
),
);
}
}