I'm trying to integrate a module with ECK, but there are a couple issues with the entity form submit handler (eck__entity__form_submit) that prevents other modules from effectively hooking into the entity-save process.

First, the handler doesn't look at updated form state values. Rather, it copies an old version of the entity, and loops through it's defined properties, updating them manually. This prevents other modules from using hook_form_alter to add additional options to entity forms, because these values won't be updated. See the uploaded image for an example of a dpm, showing how this allows the title property to be updated from Volkswagon1 to Volkswagon2, but prevents the option provided by a custom module (template picker) from being updated (from vehicle--car--tp1 to vehicle--car--tp2).

Secondly, the handler initiates $entity->save at the bottom. This seems to saves the entity prematurely, preventing any other modules with their own submit handlers from doing processing later in the process. I don't know much about entity processing, but there has to be a more universal way of saving the entity once all processing is done, similar to node_form_submit for nodes.

CommentFileSizeAuthor
ECK-entity-form-submit-handler.png351.56 KBbryanbraun
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

fmizzell’s picture

Status: Active » Postponed (maintainer needs more info)

ECK is responsible for processing the form elements that are defined as widgets through ECK's behavior system, but that shouldn't keep you from augmenting the entity form, and doing whatever you like in your own submit handler. If you implement form alter, add your own element to the form and your own submit handlers, then you can process the extra data in whatever way you like in your own submit handler. Now, from your image it seems that you have made "template_picker" an actual property of the ECK entity, if so, why no use the behavior system to define your widget instead of a form alter and a submit function?

powysm’s picture

From the above it infers there are no issues in creating a custom submit handler, however i am having problems doing just that.
Basically no matter whether i add my custom handler before, after or completely remove eck__entity__form_submit using mymodule_form_alter and the correct form id it always gets called and mine does not. I have created other custom submit handler for example for user_profile_form and that works as expected, so i have an idea what should be happening. Any suggestions?

scottm316’s picture

For others searching into this issue, I was able to call my custom submit handler by adding it elsewhere in the form and not into the traditional $form['#submit'] spot as shown in every form tutorial everywhere.

I added my submit handler using hook_form_alter and prepended it to a list of existing submit handlers (which include eck__entity__form_submit and inline_entity_form_trigger_submit):

<?php
function mymodule_form_mymodule_form_alter(&$form, &$form_state, $form_id) {
  array_unshift($form['actions']['submit']['#submit'], 'mymodule_form_submit');
}
?>
legolasbo’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

Closing old issues. Please reopen the issue with a clear description and/or steps to reproduce if this issue is still relevant.

joseph.olstad’s picture

Project: Entity Construction Kit (ECK) » File Entity (fieldable files)
Component: Code » Documentation
Category: Bug report » Support request
Status: Closed (cannot reproduce) » Reviewed & tested by the community

I can confirm that this is still an issue, however not with eck, it is a file_entity issue. I do not use eck but I am using file_entity version 7.x-2.x

To resolve the issue as described by @scottm316, I followed the instructions by @scottm316 in comment #3

Thanks @scottm316 , my submit handler now works.

DrLiri’s picture

Well it's still an issue. For example you can add a Field collection field to a form (as multiple value field!) and modify some other select field by your module (hook_form_alter) or with UI (just create a select field with a view as a data vendor). Then on the created form add at least one additional field of Field collection type and try to submit! The form wan't validate with errors, and all modified selects will be empty. And hook_entity_insert will not be called in this situation. But if you fill data just in one first field of Field collection and any other fields including selects everything will be OK, error is occurring after ajax call only.

apaderno’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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