Skip to main content
added 259 characters in body
Source Link
Adrian Cid Almaguer
  • 18.5k
  • 14
  • 79
  • 133

I found the answer:

Implementing the hook_form_FORM_ID_alter() hook you can use the comment form id (comment_comment_form) to alter the form.

The problem was that the field name is inside the author, so you need to use $form['author']['name']['#required'] = TRUE;

/**
 * Implements hook_form_FORM_ID_alter().
 */
function MODULE_form_comment_comment_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
  $form['author']['name']['#required'] = TRUE;
}

I found the answer:

/**
 * Implements hook_form_FORM_ID_alter().
 */
function MODULE_form_comment_comment_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
  $form['author']['name']['#required'] = TRUE;
}

I found the answer:

Implementing the hook_form_FORM_ID_alter() hook you can use the comment form id (comment_comment_form) to alter the form.

The problem was that the field name is inside the author, so you need to use $form['author']['name']['#required'] = TRUE;

/**
 * Implements hook_form_FORM_ID_alter().
 */
function MODULE_form_comment_comment_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
  $form['author']['name']['#required'] = TRUE;
}
Source Link
Adrian Cid Almaguer
  • 18.5k
  • 14
  • 79
  • 133

I found the answer:

/**
 * Implements hook_form_FORM_ID_alter().
 */
function MODULE_form_comment_comment_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
  $form['author']['name']['#required'] = TRUE;
}