Problem
Let's consider the example we have when building the Rules UI. We have a form, where we make use of some route parameters. The route parameter is needed during the whole form workflow, so it is set to an object property - in our case $this->rulesUiHandler
- in buildForm() as in the following example:
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, RulesUiHandlerInterface $rules_ui_handler = NULL) {
$this->rulesUiHandler = $rules_ui_handler;
}
Then, $this->rulesUiHandler is needed during validation etc. This actually works just fine as long as the form is not cached, so people we'll do it. However, as soon as the form is cached - e.g., because someone altered the form and added #ajax, the object is not initialized via buildForm() any more and thus $this->rulesUiHandler is unset. Consequently, code that relies on it fatals.
Once one uses storage in form state instead of object properties the problem is solved / worked around. However, as this is not obvious to break *later on* and the code is much simpler/nicer when using object properties, people will do it.
Fun fact: This is actually a similar issue as we had in d7 with initializing form state storage. At that time I've run into it while working on the Rules-7.x UI. :-)
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes