You are here

function comment_notify_comment_validate in Comment Notify 8

Same name and namespace in other branches
  1. 7 comment_notify.module \comment_notify_comment_validate()

Checks if the values used in the comment_notify fields are valid.

1 string reference to 'comment_notify_comment_validate'
comment_notify_form_comment_form_alter in ./comment_notify.module
Add the comment_notify fields in the comment form.

File

./comment_notify.module, line 118
This module provides comment follow-up e-mail notifications.

Code

function comment_notify_comment_validate(&$form, FormStateInterface $form_state) {
  $user = \Drupal::currentUser();

  // We assume that if they are non-anonymous then they have a valid mail.
  // For anonymous users, though, we verify that they entered a mail and let
  // comment.module validate it is real.
  if ($user
    ->isAnonymous() && $form['comment_notify_settings']['notify']['#value'] && empty($form['author']['mail']['#value'])) {
    $form_state
      ->setErrorByName('mail', t('If you want to subscribe to comments you must supply a valid e-mail address.'));
  }
}