- πΊπΈUnited States dcam
Answer given at https://drupal.stackexchange.com/a/302238. Closing.
- πΊπΈUnited States peter pulsifer
Perhaps a more direct answer is at
https://drupal.stackexchange.com/questions/229422/how-to-make-a-form-fie...It seems to depend on the type of field, and the only way I could track it down was to make the field required in the UI and then dump the $form_state array in my hook_form_alter function. For a taxonomy term entity reference field, all I needed was to set
$form['fieldname']['widget']['#required'] = true;
But for a text field, I needed
$form['fieldname']['widget'][0]['value']['#required'] = true;
Just to be careful I set
$form[fieldname']['widget']['#required'] = $form[fieldname']['widget'][0]['#required'] = $form[fieldname']['widget'][0]['value']['#required'] = true;
That's the way it comes in when I make the field required in the content type.
Just keep shooting in the dark until you hit something!