Updated: Comment #3
(Split off from #1989974: [meta] Clean up/improve consistency of Edit because it deserves its own issue. There, it just said "Make sure Edit works at all when a same entity exists multiple times on the same page (possibly in a different view mode). Also: all instances of the same entity on the same page should be updated when one of them is modified.".
Problem/Motivation
A Drupal site contains one article node: node 1. You go to the full node page for this node and on this page, you see the node 1 in full view mode, but there's also a block on the side containing node 1 in teaser view mode, as well as another block with node 1 in full view mode.
(So, the same node, 3 instances, two of which have the same view mode, and consequently the exact same HTML representation.)
When you edit either, the others don't update.
Proposed resolution
Just make it work.
The tricky case is when the view mode is different: then you need to go to the server to retrieve the entire rerendered node, because it might be rendered entirely differently now.
See the explanation and patch in #3.
Remaining tasks
None.
User interface changes
None.
API changes
None.
Related Issues
#1979784: Factor Create.js and VIE.js out of the Edit module
#1989974: [meta] Clean up/improve consistency of Edit
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | interdiff.txt | 2.32 KB | wim leers |
| #15 | edit_change_propagation-2075185-15.patch | 22.44 KB | wim leers |
| #5 | block View for testing YML files.zip | 1.51 KB | wim leers |
Comments
Comment #1
wim leersThe fundaments for this are already present. I also already had a basic (and for some reason inverse) patch for this since a long time. Attached, because it's a good starting point. It explains the challenges.
Comment #2
wim leersWe're not fixing this in the current sprint.
Comment #3
wim leersWhile working on this, I encountered two blockers:
This patch solves the problem through the following changes:
EditController::fieldForm()is slightly refactored: the rerendering of a field now happens in aprotected renderField()helper method and instead of just rendering the updated field instance's view mode, it also renders the other view modes that were received.FieldFormSavedCommandwas updated to not only return the rerendered HTML of the updated field instance, but also the rerendered HTML for the other view modes that were received.Drupal.edit.FieldModelnow has alogicalFieldIDattribute that is identical to thefieldIDattribute, minus the view mode. So, for example,fieldID = node/1/body/en/full, thenlogicalFieldID = node/1/body/en. The difference should be clear: this allows us to find all instances of the same field, no matter in which view mode they're rendered on the page.Drupal.edit.FieldModel.attributes.htmlis changed, and a newpropagateUpdatedField()method listens for that. When that method is called, it finds all other instances on the page of the same "logical field" (cfr.logicalFieldID) and rerenders them, too. If other instances use the same view mode, then it's easy: just use the same HTML as the one used to rerender the edited field instance. In the other case, step 1 guarantees that the HTML for other view modes is also available.Marking as postponed because this is blocked on #2139921 and #2141055!
Comment #4
wim leersComment #5
wim leersNow unblocked!
Attached is a straight reroll to apply cleanly against HEAD, and a .zip file containing two YML files to set up a block View for testing this feature. Just import these YML files and make sure you have at least one node, then on the front page, edit the node body or title, and BOOM, the other one updates as well! :)
Comment #6
wim leersComment #8
jessebeach commented5: edit_change_propagation-2075185-5.patch queued for re-testing.
Comment #9
jessebeach commentedI'm getting an error when editing the body of an article node on the full view, with the imported views in the sidebar.
The AJAX return object status is 'parsererror'.
PHP stack trace:
Comment #11
wim leersRoot cause determined. I'm working on PHP 5.4. Drupal 8 will soon require PHP 5.4: #2152073: Bump Drupal core's PHP requirement to 5.4.2. But, alas, for now we're stuck on 5.3. The problems you're encountering are also the reason testbot failed (testbot's still on 5.3).
To fix this, I had to introduce a cludgy work-around. Added two @todo's to make sure it's removed in #2152073. In that issue, the interdiff for this comment/reroll should be inversed to restore the clean PHP 5.4 code.
Comment #12
jessebeach commentedSo it appears that for some Views output, the content will not update, because the necessary markup is not present, specifically the
data-edit-field-idattribute. So, in the case that this attribute exists on the field, the content updates on save, as show in this image:To address the code unraveling, I opened the following issue and linked it to #2152073 (Bump Drupal core's PHP requirement to 5.4.2).
#2156793: Unravel a PHP 5.4 workaround for Edit module once Drupal requires PHP 5.4
So, this issue resolves the multiple node instance update problem without regressions.
Comment #13
jessebeach commentedI posted the hack unraveling patch here: #2156793-1: Unravel a PHP 5.4 workaround for Edit module once Drupal requires PHP 5.4
Comment #14
webchickUnfinished thought? :)
Another one? :)
Not moving down from RTBC but I don't have mental capacity to review this just yet so if it happens to get fixed in the next day or so then yay. :)
Comment #15
wim leers#12:
The demo views I attached in #5 take care of that for you :)
Supporting Views' own render pipeline is something for D8 contrib: https://drupal.org/project/edit_views.
#14: Thanks, fixed! I also fixed two JSHint errors (two missing semi-colons). I tested manually to ensure everything still works.
If you test this manually before committing: please follow the testing instructions in #5, they'll make testing a breeze :)
Comment #16
dries commentedLooks good. Small but important clean-up. Committed to 8.x.
Comment #17
wim leersNow also backported to the Drupal 7 contrib module: http://drupalcode.org/project/edit.git/commit/b199397bde82a15cec6c494ef0....