Skip to main content
1 of 3
spacecodeur
  • 1.3k
  • 3
  • 32
  • 55

Drupal 8, how disable a form programmatically?

I want disable the user register form depending some conditions. The user go to the "/user/register" page, and he must see 'Registration is disable because ...'.

From my "form_user_register_form_alter" hook, I don't find anywhere how can I disable all the form programmatically ( I mean : remove all fields form). I think I can unset all form elements, but I feel that is an ugly way ;)

Is there a method (from the FormStateInterface class) or a drupal function (for the form variable) for disable properly the form ?

Thank you !

spacecodeur
  • 1.3k
  • 3
  • 32
  • 55