I'm using Drupal 8 for a personal project and I'd like to allow only the node author to post comments.
Can you please help? I'm stuck.
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.
Sign up to join this communityI'm using Drupal 8 for a personal project and I'd like to allow only the node author to post comments.
Can you please help? I'm stuck.
although the Drupal 8 version still is on dev but you can try comment_perm module.
The Comment Permissions module enables control of commenting by user role and by node type. Additional user permissions for selected node types are added to the user access system so you can configure commenting with more control than Drupal core provides.
Update
another solution that I could suggest is using hook_form_alter.
in your custom module
function YOURMODULENAME_form_alter(&$form, FormStateInterface $form_state, $form_id) {
if($form_id == "YOUR_COMMENT_TYPE_ID"){
$node = \Drupal::request()->attributes->get('node');
if(!is_null($node) && $node->getOwnerId() != \Drupal::currentUser()->id()) {
$form['#access'] = false;
}
}
}