Problem/Motivation

When a Paragraph / Entity Reference Revisions field is present, it is always shown as changed. Even when there was no update on the paragraphs...

This makes the idea of a changed summary unusable for a Paragraphs based use case.

Proposed resolution

Investigate the use case, Support ERR / Composite recursion if needed.
This might ask for the same hierarchical display of labels such as the diff itself does.

But in short, make sure we have a meaningful message.

Remaining tasks

User interface changes

API changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

miro_dietiker created an issue. See original summary.

miro_dietiker’s picture

Issue tags: +Usability
johnchque’s picture

Assigned: Unassigned » johnchque

Yes, debugging a bit realized that that happens because when a new revision is created of the host entity, the paragraphs also create a new revision so the reference is updated and the paragraphs field appear in the revision summary.

johnchque’s picture

Being trying this but since the revision reference is updated and so, we would need to load the entity that is referenced and also the revision that was referenced to the previous host entity. Wouldn't the performance be affected with this? it would be like building the whole array for comparing in the revision listing and with all the revisions doing the same. Not really sure.

miro_dietiker’s picture

In the core issue about improving the revision logs, discussion is to autogenerate some message and persist it. I added that we should know if it was autogenerated or not.
#1807908: Autofill revision log with text that describes action like: German translation added or Spanish translation edited

So a quickfix would be to skip these kinds of ERR fields, but that would also lie as the summary would not contain relevant information if some Paragraph really changed....

My conclusion: If you want to work with Paragraphs, the summary doesn't do the job, even doesn't add value, could be even more confusion.

So i guess, we need to traverse into the composite entities and load them considering the specific revision.
And yes loading the entities revision will lead to huge IO, especially since the entity cache now doesn't work.
To keep complexity limited and summary short, we should only traverse into a nested child if the parent didn't change.
So beside specific fields that changed, we could add a better message for "Added Paragraph" or "Deleted Paragraph" and not list all their individual fields. But again, boosting complexity. ;-)

Thinking about usefulness, i think ALL or nothing. And if ALL is a performance problem, we need to allow disabling it as a setting.

We should still do all this, because the next step is to hook into entity presave and persist the autogenerated value to get rid off that load. And we want to learn from improving autogenerated messages. This is possibly the most important UX area to iterate on. The core proposal shows that experience in this area is lacking and usefulness without it is very limited. Lots of follow-ups. Many can be post-release.

johnchque’s picture

Status: Active » Needs review
FileSize
2.23 KB

Early patch. Tried for long time. Patch loops over the fields inside the entity. Right now broken cause sometimes we can add a Paragraph in a revision so the summary is not generated correctly. Need to investigate more.

Status: Needs review » Needs work

The last submitted patch, 6: paragraph_always-2806119-6.patch, failed testing.

johnchque’s picture

Status: Needs work » Needs review
FileSize
2.53 KB

Actually this makes it more readable.

Status: Needs review » Needs work

The last submitted patch, 8: paragraph_always-2806119-8.patch, failed testing.

johnchque’s picture

Status: Needs work » Needs review
FileSize
3.05 KB
1.16 KB

Let's see now. :) Interdiff added.

johnchque’s picture

Added screenshot.
When a new paragraph is added the name of the field of the host entity is displayed, when the fields inside a Paragraph are updated the name of the fields in the Paragraphs are shown.

miro_dietiker’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Thx, great to see the screenshot.

+++ b/src/DiffEntityComparison.php
@@ -288,27 +301,30 @@ class DiffEntityComparison {
+              $summary[$key . '.' . $previous_revision->getEntityTypeId()] = $value->getFieldDefinition()->getLabel();

If two nested paragraphs use the same field, this creates a clash.
We either need to use key chaning (a summary parent key argument) or simply numeric keys that are appended.

As discussed directly, we need some inline comments explaining the specific (pretty complex) cases.
And finally, we will need test coverage.

johnchque’s picture

Actually this can be much cleaner, I'm trying something now. Will upload a patch soon.

johnchque’s picture

Worked on this, but this makes me realize that loading the entity that a node was pointing and load the revision of the pointed revision and then comparing might be harder than expected.

miro_dietiker’s picture

Priority: Major » Critical

We need a decision, preferrably a solution, for the release.

johnchque’s picture

OK, discussed with Miro, we will use the EntityParser code to make it recursive and nice for the user. :)

johnchque’s picture

Status: Needs work » Needs review
FileSize
4.01 KB

Started from 0. Now we have a better display of the changed fields.

Status: Needs review » Needs work

The last submitted patch, 17: paragraph_always-2806119-17.patch, failed testing.

johnchque’s picture

I was wondering if the initial revision should have a comment like "Initial revision." instead of "No changes." That would be much nicer IMO.

johnchque’s picture

Ups, just realized there are some small problems when an entity is present in one revision and not in the other one, still needs work.

johnchque’s picture

Status: Needs work » Needs review
FileSize
5.39 KB
3.09 KB
90.54 KB

This should work nicer. And also test fixed.
Looks like this now:

johnchque’s picture

Status: Needs review » Needs work

EDIT: Wrong comment.

johnchque’s picture

Status: Needs work » Needs review

The last submitted patch, 14: paragraph_always-2806119-14.patch, failed testing.

tduong’s picture

Status: Needs review » Needs work

Small small re-considerations:

  1. +++ b/src/DiffEntityComparison.php
    @@ -268,15 +268,57 @@ class DiffEntityComparison {
    +    // Check if the revision has a revision log, if not the auto generate it.
    

    I would say this
    // Check if the revision has a log message.
    and
    // Auto generate a revision log.
    above the if ($auto_generated)

  2. +++ b/src/DiffEntityComparison.php
    @@ -268,15 +268,57 @@ class DiffEntityComparison {
    +    }
    +    if ($auto_generated) {
    

    Then would add a new line.

  3. +++ b/src/DiffEntityComparison.php
    @@ -268,15 +268,57 @@ class DiffEntityComparison {
    +      // If there is a previous revision, load the values of each and add to the
    +      // summary the ones that have changed.
    

    Not sure what you meant, but maybe
    // If there is a previous revision, load its values and add the changed
    // ones to the summary.

  4. +++ b/src/DiffEntityComparison.php
    @@ -268,15 +268,57 @@ class DiffEntityComparison {
    +          // If the field is present in the left entity, compare values, if not
    +          // add it to the summary. Unset the ones already added.
    


    // Unset the field, which value is not changed. Add it to the summary
    // if it is changed or new.

  5. +++ b/src/DiffEntityComparison.php
    @@ -268,15 +268,57 @@ class DiffEntityComparison {
    +          if (isset($left_values[$key])) {
    +            if ($value != $left_values[$key]) {
    +              $revision_summary[] = $value['label'];
    +            }
    +            unset($left_values[$key]);
    +          }
    +          else {
    +            $revision_summary[] = $value['label'];
    +          }
    

    And I would shorten this check as

    if (isset($left_values[$key]) && ($left_values[$key] != $value)) {
       unset($left_values[$key]);
    }
    else {
        $revision_summary[] = $value['label'];
    }
    
  6. +++ b/src/DiffEntityComparison.php
    @@ -268,15 +268,57 @@ class DiffEntityComparison {
    +        // Loop over the left values that remain and add them if not present in
    +        // the right entity.
    

    // Add the remaining left values not present in the right entity..

    And separate this foreach-block from the one above.

  7. +++ b/src/DiffEntityComparison.php
    @@ -285,31 +327,36 @@ class DiffEntityComparison {
    +     $result = array();
    

    []

johnchque’s picture

Status: Needs work » Needs review
FileSize
5.35 KB
2.42 KB

Comments changed.
5. of the comment above cannot be done, that would mean change in the logic, after comparing a field no matter it has changed or not, if present in the right side, I unset it, so just remaining fields are added when looping on the left values.

johnchque’s picture

This might change when #2810039: Diff for 'Sticky at top of lists' does not work is committed. Will need to check again after that one is committed.

miro_dietiker’s picture

Status: Needs review » Fixed
Issue tags: -Needs tests
+++ b/src/DiffEntityComparison.php
@@ -268,15 +268,57 @@ class DiffEntityComparison {
+    $revision_summary = [];
...
       $revision_summary = Xss::filter($revision->getRevisionLogMessage());
       if ($revision_summary == '') {
...
+        $revision_summary = [];
...
+          $revision_summary = 'Changes on: ' . implode(', ', $revision_summary);

That's a strange mix of array and string. We try to be uniform.

I still committed to help move forward, but i think we should improve it a bit.

johnchque’s picture

Status: Fixed » Needs review
FileSize
3.61 KB

This should be nicer and more readable. :)

miro_dietiker’s picture

Status: Needs review » Needs work

I then reviewed that terminology of variables (left, right, previous) and confirmed that this naming is fine.
left + right is with two references selected (could be a sequence).
But this method has one revision, plus optionally the previous one. left + right is very confusing especially if left is getting optional and sequence changes with right first.

+++ b/src/DiffEntityComparison.php
@@ -259,23 +259,24 @@ class DiffEntityComparison {
+    $summary_elements = [];
...
+        $summary_elements = [];

This is double reset.

miro_dietiker’s picture

Status: Needs work » Needs review
FileSize
2.27 KB

Reverting the renames.

johnchque’s picture

Status: Needs review » Reviewed & tested by the community

Much better IMHO.

  • miro_dietiker committed fde325a on 8.x-1.x
    Issue #2806119 by yongt9412, miro_dietiker: Paragraph always changed in...
miro_dietiker’s picture

Status: Reviewed & tested by the community » Fixed

Committed. :-)

Status: Fixed » Closed (fixed)

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