You are here

function social_comment_form_reply_validate in Open Social 10.3.x

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_comment/social_comment.module \social_comment_form_reply_validate()
  2. 8 modules/social_features/social_comment/social_comment.module \social_comment_form_reply_validate()
  3. 8.2 modules/social_features/social_comment/social_comment.module \social_comment_form_reply_validate()
  4. 8.3 modules/social_features/social_comment/social_comment.module \social_comment_form_reply_validate()
  5. 8.4 modules/social_features/social_comment/social_comment.module \social_comment_form_reply_validate()
  6. 8.5 modules/social_features/social_comment/social_comment.module \social_comment_form_reply_validate()
  7. 8.6 modules/social_features/social_comment/social_comment.module \social_comment_form_reply_validate()
  8. 8.7 modules/social_features/social_comment/social_comment.module \social_comment_form_reply_validate()
  9. 8.8 modules/social_features/social_comment/social_comment.module \social_comment_form_reply_validate()
  10. 10.0.x modules/social_features/social_comment/social_comment.module \social_comment_form_reply_validate()
  11. 10.1.x modules/social_features/social_comment/social_comment.module \social_comment_form_reply_validate()
  12. 10.2.x modules/social_features/social_comment/social_comment.module \social_comment_form_reply_validate()

Form validation handler for comment_form().

Validate replies to comments deeper than 1.

1 string reference to 'social_comment_form_reply_validate'
social_comment_form_comment_form_alter in modules/social_features/social_comment/social_comment.module
Implements hook_form_FORM_ID_alter().

File

modules/social_features/social_comment/social_comment.module, line 149
The Social comment module.

Code

function social_comment_form_reply_validate($form, FormStateInterface $form_state) {

  // Get parent comment ID.
  if (!($pid = \Drupal::routeMatch()
    ->getParameter('pid'))) {
    return;
  }

  /** @var \Drupal\comment\CommentInterface $comment */
  $comment = \Drupal::entityTypeManager()
    ->getStorage('comment')
    ->load($pid);
  if ($comment
    ->bundle() === 'post_comment') {
    $form_state
      ->setErrorByName('', t('Replies for comments on posts are not allowed'));
  }
  elseif (!empty($comment
    ->getParentComment())) {
    $form_state
      ->setErrorByName('', t('Replies to comments deeper than 1 is not allowed'));
  }
}