With Drupal 8.0.0-beta13, a fatal error is issued from the field_collection module:

PHP Fatal error:  Class 'Drupal\system\Controller\FormAjaxController' not found in /home/vagrant/docroot/modules/contrib/field_collection/src/Controller/FieldCollectionWidgetAjaxController.php on line 16

On further research, it looks like FormAjaxController was removed from core as a result of #2502785: Remove support for $form_state->setCached() for GET requests
There is a change record at https://www.drupal.org/node/2501435 but it does not yet describe the replacement for using FormAjaxController.

CommentFileSizeAuthor
#2 fc-ajax-fix-2544676-2.patch7.71 KBpaulmckibben

Comments

paulmckibben’s picture

Been trying to understand the implications of this change. According to the issue description in #2502785: Remove support for $form_state->setCached() for GET requests, field_collection and any other contrib module that used FormAjaxController will have to be refactored to use an ajax callback instead of a URL.

What I think this means:

  • FieldCollectionWidgetAjaxController should be removed entirely, and the corresponding route removed from field_collection.routing.yml.
  • The functionality from this class handling ajax removal must be moved to a callback function, presumably in FieldCollectionEmbedWidget.
  • In FieldCollectionEmbedWidget::formElement(), instead of $form['#ajax']['url'], use $form['#ajax']['callback'], which will use the above callback function.
paulmckibben’s picture

Status: Active » Needs work
StatusFileSize
new7.71 KB

I have an initial patch (attached). However, I have found that when I edit a node that uses a multi-valued field_collection field, after saving the node, the field collections disappear from it. I'm not sure if it is because of this patch or part of another issue. More investigation required.

I welcome anyone's help.

floretan’s picture

I ran into the same issue that field values are not getting stored anymore. This happens independently of this patch.

floretan’s picture

Status: Needs work » Reviewed & tested by the community

I solved the issue with the saved values in #2558001: Field values are not saved.

This patch applies cleanly and works as expected.

  • paulmckibben authored 756a936 on 8.x-1.x
    Issue #2544676 by paulmckibben: Replaced FormAjaxController
    
jmuzz’s picture

Status: Reviewed & tested by the community » Fixed

Thanks, committed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.