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?

2 Answers 2


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 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.