Skip to content

Instantly share code, notes, and snippets.

@skounis
Created July 7, 2020 10:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skounis/78247e173562ab930a271c018cab78e3 to your computer and use it in GitHub Desktop.
Save skounis/78247e173562ab930a271c018cab78e3 to your computer and use it in GitHub Desktop.
function fut_content_preprocess_field(&$variables) {
$element = $variables['element'];
if ($element['#field_type'] == 'comment') {
if (_fut_content_prevent_comments()) {
unset($variables['comment_form']);
}
}
}
function fut_content_comment_links_alter(array &$links, CommentInterface $entity, array &$context) {
if (_fut_content_prevent_comments()) {
unset($links["comment"]["#links"]["comment-reply"]);
}
}
function _fut_content_prevent_comments() {
$current_user = \Drupal::currentUser();
$group = \Drupal::service('fut_group.request_entity_extractor')->getGroup();
$prevent = isset($group) && !$group->hasPermission('comment group content', $current_user);
return $prevent;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment