Should I save temporary data in $form_state or in my form class? As far as I can see, there are two ways of storing temporary data when working with complex forms in Drupal 8.


$form_state-&gt;set('key', 'value'). The value ends up in $form_state['storage']['value'], and I can use it other places because it is passed around from function to function.
Make a non-static property inside class MyForm extends FormBase. The value is also accessible everywhere I need it, since all of the form functions are in one class.


After browsing through a lot of core EntityForm code today, it seems that both are used! Is any of the above necessarily "better" or more in line with "The Drupal Way"?

Related question: It seems that there is a 1:1 mapping between an instance of MyForm and the $form_state variable. Why then, is $form_state not implemented as a non-static class property? Then it wouldn't be necessary to pass it from function to function. The same can be asked of the $form variable.
While the storage in $form_state can be cached, the class property can't. So if you build a multistep form you would need to use the first option.

And a validate or submit function is not necessarily in the same class or in no class at all if it is defined in a hook. This also answers the related question.