Problem/Motivation

When the Editable View's 'save' button is clicked, all entities in the view are saved, regardless of whether the user made any changes to them or not. This is problematic because:

- it can take a very long time for a View with a large number of rows
- it changes timestamps on entities when no change has been made

Proposed resolution

Create a custom Views field handler, which outputs a checkbox for the form, so that each row of the View has its own checkbox.
This checkbox then determines whether or not to save the row: a checked value saves the row.

The handler's admin options should have a setting for the checkbox's default value.

If the field is not present on a View, the current behaviour remains.

Remaining tasks

Create the field handler.

Original report by @SanduCiprian

when i click save, it saves all the nodes. i want to save only the nodes that i edited. in this way i want keep the node's last update date untouched.

Comments

joachim’s picture

As documented in the code, there is nothing I can do here.

How can the code decide if a node has been edited or not?

SanduCiprian’s picture

by comparing if the fields are different from what is stored in db

joachim’s picture

That will make it slower though!

I'm open to a patch for this, but it will be a pretty complex piece of work.

yorguey31’s picture

It might be be pretty hard but saving a lot of unchanged data is bit time consuming too.

Perhaps a more hmi way, just marking entities displayed with a flag 'not modified' and reverting it something in the corresponding line/entities is modified....
Or something to keep link with the original non editable filed and compare displayed value used as a chached value...

Sorry for my naive way of thinking ...just trying to help ;-)

joachim’s picture

> just marking entities displayed with a flag 'not modified' and reverting it something in the corresponding line/entities is modified....

To determine whether an entity has been edited or not, the code would have to load the original entity, and compare it with the version that's been built from form values. That in itself is a bit tricky, as there are a few quirks with FieldAPI field arrays.

The bigger problem though is that it's impossible to do this for entities that are about to be created for empty relationships, because you can't tell the difference between a value that's a default for a field, and a value that's there because the user wants it to be there.

btopro’s picture

Would it be possible to have a checkbox that essentially marks the node as being edited? Or when a field is modified (Detected via JS) that it sets a hidden value. This hidden value can then be tested for True/False and only save the entities in that row when the row has this modification detected. This would be much more efficient then needing to do a full item comparison.

joachim’s picture

It would -- it would need to be a custom Views field, and then the submit handlers would pick up on its presence and use that instead of comparing field values.

Unfortunately, it's not something that I need for my current project, so it's not something I'd be working on.

Sata’s picture

Issue summary: View changes

https://api.drupal.org/api/drupal/includes%21form.inc/function/drupal_fo...

>$form_state: A keyed array containing the current state of the form. Most important is the $form_state['values'] collection, a tree of data used to simulate the incoming $_POST information from a user's form submission. If a key is not filled in $form_state['values'], then the default value of the respective element is used. To submit an unchecked checkbox or other control that browsers submit by not having a $_POST entry, include the key, but set the value to NULL.

...

https://api.drupal.org/api/drupal/includes%21form.inc/function/form_stat...

>Retrieves default values for the $form_state array.

If you can load the defaults, should be able to compare the data.

e.g. @
$default_state = form_state_defaults();
... compare $form_state to $default_state -- flag values as default
... compare $field_instance to $form_state w/ flags.

joachim’s picture

form_state_defaults() is about setting up the $form_state array with initial values when building a form; it doesn't have anything to do with default values for the actual form elements.

You'd need to get the original value either out of the original form, or from the original entities. IIRC the entities are in the form somewhere.

The other problem is with the functionality with non-required relationships which allow entities to be created. You simply can't tell whether a value is the default value for the field, or a value the user's entered.

matt2000’s picture

I'd like to suggest an option to add a Views "field" that provides a Save button per row (like VBO) to replace the one Save button for the page. I think this would resolve the core need here.

joachim’s picture

Sounds reasonable, provided it's an option. My use case for this module is a form where the user makes lots of changes and saves only once. File a new issue and post a patch! :)

Darth_Beholder’s picture

Yes, it would be great to have a Save button per row. Waiting for the patch :)

dexiecarla’s picture

Subscribing in this.

jalilkhan’s picture

I think checkbox column to be added so user have option to tick checkbox which they have edited. In this way, only edited node to be saved.

joachim’s picture

Might any of the commenters who are interested in this feature be able to work on a patch?

jalilkhan’s picture

i am interested @joachim.

rooby’s picture

Title: save only edited nodes » Save only edited entities
Version: 7.x-1.0-beta4 » 7.x-1.x-dev

I agree it is not great to save all rows all the time.
It creates incorrect data in regards to last updated timestamps and unnecessary revisions.

Although I also see where joachim is coming from, it's not trivial to compare old & new values to work it out.

Would it be possible to have a checkbox that essentially marks the node as being edited? Or when a field is modified (Detected via JS) that it sets a hidden value.

Relying on javascript is not ideal.

The save button per row idea would probably work well for some use cases (still needs a ticket of its own made though).

Also #2046257: Editing only nodes with changed field, not all of them seems like a duplicate.

joachim’s picture

Title: Save only edited entities » Add checkbox to determine which rows to save
Issue summary: View changes

I've updated the summary & title of this issue to reflect the solution I feel should be pursued here.

#2046257: Editing only nodes with changed field, not all of them can remain, as the patch there is seeking to automatically detect whether entities have been changed -- something which can only work when there are no entities being created, so not as flexible a solution.

caschbre’s picture

Has anyone attempted/started a patch to add checkboxes as described above? If not, I may try tackling this next week as it's functionality we're looking to have.

Andrej Galuf’s picture

Yes, but I'm also trying to reuse the checkboxes offered by vbo (else my forms would end up with too many checkboxes). A potential solution would be reusing vbo checkboxes if they are available and copying their solution if they are not.

As for #2046257: Editing only nodes with changed field, not all of them, I believe we can do that through javascript - detect when information in the field has changed and automatically tick the checkbox on focusout. Should solve about three problems at once :)

ultrandy89’s picture

Any progress? My order timestaps are also getting messed up now too lol

abrlam’s picture

Check out the patch in the other issue. No JS/Checkbox is needed.

https://www.drupal.org/node/2046257#comment-11837819