public function OgTestEventSubscriber::moderatorsCanManageComments in Organic groups 8
Allows moderators to edit and delete comments in all groups.
Parameters
\Drupal\og\Event\GroupContentEntityOperationAccessEventInterface $event: The event that fires when an entity operation is being performed on group content.
File
- tests/
modules/ og_test/ src/ EventSubscriber/ OgTestEventSubscriber.php, line 49
Class
- OgTestEventSubscriber
- Event subscribers for testing Organic Groups.
Namespace
Drupal\og_test\EventSubscriberCode
public function moderatorsCanManageComments(GroupContentEntityOperationAccessEventInterface $event) : void {
if ($this->state
->get('og_test_group_content_entity_operation_access_alter', FALSE)) {
// Moderators should have access to edit and delete all comments in all
// groups.
$is_comment = $event
->getGroupContent()
->getEntityTypeId() === 'comment';
$user_can_moderate_comments = $event
->getUser()
->hasPermission('edit and delete comments in all groups');
if ($is_comment && $user_can_moderate_comments) {
$event
->grantAccess();
}
}
}