Make Metatag description field required in Drupal 9

37 Views Asked by At

I need to ensure that the description field in Metatag module is required. How can I do that?

Tried adding this code to metatag.module (to create a custom patch later if it worked) from this article, but this is for Drupal 7. I'm working in Drupal 9:

function metatag_form_alter(&$form, &$form_state, $form_id) {
  if (isset($form['metatags'])) {
    if (isset($form['metatags']['description']['value'])) {
      $form['metatags']['description']['value']['#required'] = TRUE;
    }
    if (isset($form['metatags']['keywords']['value'])) {
      $form['metatags']['keywords']['value']['#required'] = TRUE;
    }
  }
}

But that didn't work.

Thank you in advance!

0

There are 0 best solutions below