2

I am pretty new to Drupal and simply cant figure it out. I've set up a comment type for a content type. I want to use the default subject field as comment title and want to make it required.

I know, I could simply create a text field named "title" and make it required. But if I manage the comments in backend, there will always be (no subject) in the comments overview list. Is there any way to set it to required?

Thanks in advance!

1 Answer 1

5

Here is how, you will need to create a custom module , and add this ... to yourmodule.module file ...

/**
 * Implements hook_form_alter().
 */
function yourmodule_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id)
{
  if ($form_id === 'comment_comment_form') {

    $form['subject']['widget'][0]['value']['#required'] = TRUE;

  }
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.