In the function editablefields_form_submit when a changed field is saved the whole entity with old values are getting saved. This works quite well, but if you have several editable fields on a page and change them a bit fast the changed fields are getting overriden by the last change. I've made a patch that fixes this by only saving the changed field.

Inspiration for this patch came from this blogg: http://blog.urbaninsight.com/2011/10/24/saving-nodes-fields-without-savi...

Comments

mnlund’s picture

And the patch

dmadruga’s picture

I was having problems editing a node with taxonomy terms reference fields.
Your patch solved my problem! Tks.

I just needed to make a tiny modification on the way it clears the cache (otherwise I get an PDOException table cache_entity_node doesn't exist):

Replace
cache_clear_all($element['#entity_id'], 'cache_entity_' . $element['#entity_type']);

By
entity_get_controller($element['#entity_type'])->resetCache(array($element['#entity_id']));

mnlund’s picture

Status: Active » Needs review
StatusFileSize
new2.17 KB

Nice catch. It wasn't tested enough with other entity types. I have added a new patch with the changes.

andros’s picture

This patch works for me.
Is there no one to put this in the dev version?

wasare’s picture

Priority: Normal » Major
Issue summary: View changes
Renee S’s picture

This no longer applies, but the problem still exists, the whole entity is being loaded/saved.

Renee S’s picture

Status: Needs review » Needs work
milos.kroulik’s picture

I confirm, that this doesn't work on latest dev.

e5sego’s picture

Regarding to this issue, I found that one change to an editable field within a view can influence values on other fields, which have been changed in meantime otherwise.

For example:
Field a - editable, shown on views table
Field b - normal field

1. open the views table
2. change value of b via edit node form
3. save value of a on the view (without reload)

This causes value of b is reset to the time where the views was opened (1.) Is this by design or a bug?

ilyasmdgh’s picture

The patch worked for me on the node page but does not on the views page. On the views page it looks like it saved but on refresh the old value returns.

dreamer777’s picture

The same problem as #10 exists in views page. Any ideas, how this cool feature could be implemented?

nimek’s picture

Tested in latest dev

line 561 (probably)

Change this

 entity_save($element['#entity_type'], $entity);

To this

 field_attach_update($element['#entity_type'], $entity);

That way is faster and more eficient but be aware that field_attach_update will not call node hooks like node_presave or node_update

OR more complex solution where we really save only changed field.
line 317

  $form_state['#field_name'] = $field['field_name'];

line 482

  $form_state['#field_name'] = $views_field->field_info['field_name'];

line 561

$entity_info = entity_get_info($element['#entity_type']);
	$new_entity = new stdClass();
    $new_entity->{$entity_info['entity keys']['id']} = $element['#entity_id'];
    $new_entity->type = $element['#entity_type']; 
    $new_entity->{$entity_info['entity keys']['bundle']} = $element['#bundle'];
    $new_entity->{$form_state['#field_name']} = $entity->{$form_state['#field_name']};
    field_attach_presave($element['#entity_type'], $new_entity);
    field_attach_update($element['#entity_type'], $new_entity);
    entity_get_controller($element['#entity_type'])->resetCache(array($element['#entity_id']));
    $form_state['rebuild'] = TRUE;

Works great :).
I can get maintainance of this module if somebody tell me how because I like it very much and it has a lot of panding patches.

nimek’s picture

BAsed on #12 I created patch with some adjustments.

nimek’s picture

Status: Needs work » Needs review
sadashiv’s picture

I was also facing a similar issue i.e.
1) Open the page with editable field in first tab
2) Now open the entity (node, or profile) in second tab.
3) Update few fields in the entity and save (don't update the editable field but other than that)
4) Go back to first tab and edit the editable field.

Now when I check I find that the fields modified in second tab are all rolled back. I did a simple change to fix this.

-  $entity = $form_state['editablefields_entities'][$element['#entity_type']][$element['#entity_id']];
+  $entity = entity_load_unchanged($element['#entity_type'], array($element['#entity_id']));

I was happy to provide a patch but can see the dev is different so just a diff.

Thanks,
Sadashiv.

joelpittet’s picture

Status: Needs review » Needs work

Can we check access control first that the entity_save() is providing?