Spin-off from #1499596-96: Introduce a basic entity form controller:

I noticed that due to $controller->form_state the form state gets serialized *into itself* when it is cached. I've discussed that with plach and we agreed to remove $controller->form_state for now and just pass it on to respective methods always. We may want to simplify the getEntity() calls to do not require the passed on form-state again in the follow-up where we fix the controller being still duplicated to $form and $form_state.

To be completed.


fago’s picture

Right now the controller gets into $form when it is assigned as callback, e.g. when assigned as #submit handler. Then it also in $form_state['controller'], however both arrays get serialized independently of each other, what means we'll get two controller instances after cache retrieveal.

That's something we want to fix. Right now, this is no problem as the controller contains no state though, but that might change.

sun’s picture

Hm. I don't quite get it.

Why do we store the controller in $form?

$form_state['build_info']['callback'] = array($controller, 'build');

It looks like we could simply replace that?

$form_state['build_info']['callback'] = array(get_class($controller), 'build');

For a #cache'd form, the callback is not re-invoked on subsequent requests. For non-#cache'd forms it is.

To me this actually looks like as if $controller should be a $factory here...?

fago’s picture

The controller also adds itself to button handles, e.g. $form['button']['#submit'] which are executed on cached forms.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.