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
Comment #1
joachim CreditAttribution: joachim commentedAs documented in the code, there is nothing I can do here.
How can the code decide if a node has been edited or not?
Comment #2
SanduCiprian CreditAttribution: SanduCiprian commentedby comparing if the fields are different from what is stored in db
Comment #3
joachim CreditAttribution: joachim commentedThat will make it slower though!
I'm open to a patch for this, but it will be a pretty complex piece of work.
Comment #4
yorguey31 CreditAttribution: yorguey31 commentedIt 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 ;-)
Comment #5
joachim CreditAttribution: joachim commented> 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.
Comment #6
btopro CreditAttribution: btopro commentedWould 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.
Comment #7
joachim CreditAttribution: joachim commentedIt 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.
Comment #8
Sata CreditAttribution: Sata commentedhttps://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.
Comment #9
joachim CreditAttribution: joachim commentedform_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.
Comment #10
matt2000 CreditAttribution: matt2000 commentedI'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.
Comment #11
joachim CreditAttribution: joachim commentedSounds 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! :)
Comment #12
Darth_Beholder CreditAttribution: Darth_Beholder commentedYes, it would be great to have a Save button per row. Waiting for the patch :)
Comment #13
dexiecarla CreditAttribution: dexiecarla commentedSubscribing in this.
Comment #14
jalilkhan CreditAttribution: jalilkhan commentedI 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.
Comment #15
joachim CreditAttribution: joachim commentedMight any of the commenters who are interested in this feature be able to work on a patch?
Comment #16
jalilkhan CreditAttribution: jalilkhan commentedi am interested @joachim.
Comment #17
rooby CreditAttribution: rooby commentedI 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.
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.
Comment #18
joachim CreditAttribution: joachim commentedI'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.
Comment #19
caschbre CreditAttribution: caschbre commentedHas 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.
Comment #20
Andrej Galuf CreditAttribution: Andrej Galuf commentedYes, 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 :)
Comment #21
ultrandy89 CreditAttribution: ultrandy89 commentedAny progress? My order timestaps are also getting messed up now too lol
Comment #22
abrlam CreditAttribution: abrlam commentedCheck out the patch in the other issue. No JS/Checkbox is needed.
https://www.drupal.org/node/2046257#comment-11837819