I am trying to build a module that provides a widget. The widget is based on FileWidget and I would like to add some fields from another form to the existing FileWidget form. I would like to save the content of these fields after submit of the parent form.

So I loaded the form, from which I want to add some elements, in my widgets process method, with \Drupal::service('entity.form_builder')->getForm($entity) but I am having troubles extracting specific field elements. If I add a new form element, let's say a textfield, it works as intended and I can access the user input of this field in hook_entity_presave, but sadly not with elements from an existing form.

In Drupal 7 this could be done with the function field_attach_form() but this is not possible anymore.

Is there a clean way in Drupal 8 for this?

  • Hey @tobyte, did you find a solution? – Mr.B Nov 22 '16 at 1:30
  • Actually I did, I ended up using the EntityFormDisplay like this: Gist – tobyte Nov 22 '16 at 17:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.