If I wanted to rebuild a form in Drupal 7, conditional on the state of the form, I would do something like this:

if (isset($form_state['values']['foo'])) {

Now, $form_state is an object in Drupal 8. What would be the best equivalent?


Pretty much $form_state->getValue('foo');.

See the docs page for getValue.


I belive that the equivalent to isset() is

if ($form_state->hasValue('foo')) {

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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