Problem/Motivation

The paragraphs are a composite part of the encapsulating node.
The diff currently shows nothing at all.

Proposed resolution

Provide a diff plugin for the paragraphs field type (currently entity reference revision), see also #2430209: Create own fieldtype for Paragraphs
And make sure the paragraph types have proper diff configuration for their fields.

Then, the encapsulating node (or whatever) containing paragraphs can show a nice diff.

Remaining tasks

User interface changes

API changes

CommentFileSizeAuthor
#95 interdiff-2433099-92-95.txt367 bytesjohnchque
#95 provide_a_custom_diff-2433099-95.patch5.33 KBjohnchque
#94 diff_test_dependency.patch367 bytesjohnchque
#92 interdiff-2433099-90-92.txt4.18 KBjohnchque
#92 provide_a_custom_diff-2433099-92.patch5.69 KBjohnchque
#90 interdiff-2433099-86-90.txt3.85 KBjohnchque
#90 provide_a_custom_diff-2433099-90.patch5.41 KBjohnchque
#88 Screenshot from 2016-04-21 13:54:59.png37.47 KBjohnchque
#86 provide_a_custom_diff-2433099-86.patch1.56 KBjohnchque
#81 interdiff-provide_a_custom_diff-2433099-77-81.txt1.59 KBedurenye
#81 provide_a_custom_diff-2433099-81.patch5.69 KBedurenye
#77 interdiff-provide_a_custom_diff-2433099-66-77.txt2.23 KBedurenye
#77 provide_a_custom_diff-2433099-77.patch5.69 KBedurenye
#71 Selection_678.png25.12 KBjeroen.b
#66 provide_a_custom_diff-2433099-66.patch5.8 KBLKS90
#63 provide_a_custom_diff-2433099-63.patch7 KBLKS90
#59 provide_a_custom_diff-2433099-59.patch10.04 KBLKS90
#59 interdiff_50-59.txt287 bytesLKS90
#56 interdiff_50-56.txt659 bytesLKS90
#56 provide_a_custom_diff-2433099-56.patch10.07 KBLKS90
#56 Screen Shot 2015-06-18 at 16.53.34.png44.84 KBLKS90
#53 Screen Shot 2015-06-18 at 15.42.25.png31.84 KBLKS90
#50 provide_a_custom_diff-rebase-2433099-50.patch10.04 KBLKS90
#47 Screen Shot 2015-06-18 at 11.43.36.png35.65 KBLKS90
#26 paragraphs_2433099_diff_26.patch252 bytesmiro_dietiker
#23 provide_a_custom_diff-2433099-23-interdiff.txt10.85 KBsasanikolic
#23 provide_a_custom_diff-2433099-23.patch9.26 KBsasanikolic
#22 paragraphs_2433099_diff_test.patch252 bytesmiro_dietiker
#17 provide_a_custom_diff-2433099-17-interdiff.txt5.49 KBsasanikolic
#17 provide_a_custom_diff-2433099-17.patch7.3 KBsasanikolic
#14 provide_a_custom_diff-2433099-14-interdiff.txt3.68 KBsasanikolic
#14 provide_a_custom_diff-2433099-14.patch5.2 KBsasanikolic
#12 provide_a_custom_diff-2433099-12.patch1.52 KBAnushka-mp
#12 provide_a_custom_diff-2433099-12-interdiff.txt877 bytesAnushka-mp
#5 provide_a_custom_diff-2433099-5.patch1.55 KBAnushka-mp
#4 Screen Shot 2015-03-25 at 15.48.15.png135.42 KBAnushka-mp
#2 provide_a_custom_diff-2433099-2.patch1.66 KBAnushka-mp

Comments

miro_dietiker’s picture

A good example for a previously unsupported field type that needs integration with a plugin.
#2424267: Provide a diff plugin for comment settings

Anushka-mp’s picture

Status: Active » Needs review
StatusFileSize
new1.66 KB

The plugin for diff module since there is no field type for paragraphs the plugin is based on the field type entity_reference_revisions.
Created the issue #2459237: Services for diff plugin for adding the services for the plugin

Status: Needs review » Needs work

The last submitted patch, 2: provide_a_custom_diff-2433099-2.patch, failed testing.

Anushka-mp’s picture

Status: Needs work » Needs review
StatusFileSize
new135.42 KB

Adding screens.

Anushka-mp’s picture

StatusFileSize
new1.55 KB
+++ b/src/Plugin/diff/EntityReferenceRevisionsFIeldBuilder.php
@@ -0,0 +1,49 @@
+              //$result_text[$id] = 'Field id :' . $field_id . '. Entity id: ' . $id . '. Text:' . $text[0];

Removed this line.

Status: Needs review » Needs work

The last submitted patch, 5: provide_a_custom_diff-2433099-5.patch, failed testing.

miro_dietiker’s picture

Nice work. That already helps a lot to understand what's happening.

When looking at the screenshots provided, i realise that a paragraph with multiple items is offered as one field.
It would be very nice, if diff would understand recursive structure and we could flatten the paragraph items into top level items.
I guess that's super followup fancyness.

lhangea’s picture

Anushka-mp’s picture

Status: Needs work » Needs review
lhangea’s picture

Status: Needs review » Needs work

Now that the entity parser service is injected in the base plugin class we should definitely use it :)

Status: Needs work » Needs review
Anushka-mp’s picture

The entity parser service used from the injected config.
Needs test coverage for this.

sasanikolic’s picture

Added the tests.

Status: Needs review » Needs work

The last submitted patch, 14: provide_a_custom_diff-2433099-14.patch, failed testing.

miro_dietiker’s picture

Issue tags: -Needs tests

Yeah, good start.

Please put this into a separate test method about diff. Will be extended with more diff cases in future.

  1. +++ b/src/Tests/ParagraphsAdministrationTest.php
    @@ -186,6 +189,78 @@ class ParagraphsAdministrationTest extends WebTestBase {
    +    $this->drupalPostForm(NULL, NULL, t('Add Text + Image'));
    +    $this->drupalPostForm(NULL, NULL, t('Add Text + Image'));
    

    Pick "Text" only. Image part is unused in this sequence.

  2. +++ b/src/Tests/ParagraphsAdministrationTest.php
    @@ -186,6 +189,78 @@ class ParagraphsAdministrationTest extends WebTestBase {
    +    // Ccheck, if the second paragraph is changed.
    ...
    +    // Ccheck, if the second paragraph is changed.
    

    Cc => C

sasanikolic’s picture

Status: Needs work » Needs review
Related issues: +#2490586: Use EntityChangedTrait for paragraphs
StatusFileSize
new7.3 KB
new5.49 KB

Separated the test and added a field for text only.

Status: Needs review » Needs work

The last submitted patch, 17: provide_a_custom_diff-2433099-17.patch, failed testing.

The last submitted patch, 17: provide_a_custom_diff-2433099-17.patch, failed testing.

berdir’s picture

+++ b/src/Tests/ParagraphsAdministrationTest.php
@@ -186,6 +189,109 @@ class ParagraphsAdministrationTest extends WebTestBase {
+
+  public function testParagraphsDiff() {
+
+    $this->drupalGet('admin/structure/paragraphs_type');

It should be a separate test *class*, not just method. With a @dependencies diff annotation.

It also needs a test_dependencies entry in the info file for the diff module. Please upload that as a separate patch, as that needs to be committed first, then we need to wait for testbot dependencies to rebuild, then it should work.

miro_dietiker’s picture

Status: Needs work » Needs review
StatusFileSize
new252 bytes

Providing the fix to add test dependencies to diff first.

sasanikolic’s picture

Separated the test into a new class and added the @dependencies.

Status: Needs review » Needs work

The last submitted patch, 23: provide_a_custom_diff-2433099-23.patch, failed testing.

miro_dietiker’s picture

Status: Needs work » Needs review
StatusFileSize
new252 bytes

Oh, in order to make the tests pass, we first need a commit of the diff test dependency.

The last submitted patch, 23: provide_a_custom_diff-2433099-23.patch, failed testing.

miro_dietiker’s picture

Status: Needs review » Reviewed & tested by the community

Plz commit the test dependency first.

The last submitted patch, 23: provide_a_custom_diff-2433099-23.patch, failed testing.

miro_dietiker’s picture

Status: Reviewed & tested by the community » Needs review

The original patch still needs review. I guess the dependencies need a rebuild now that is only done once per day. Let's retest in 24h.

The last submitted patch, 23: provide_a_custom_diff-2433099-23.patch, failed testing.

miro_dietiker’s picture

So the dependency still doesn't work...
Next step: Crying out loud. ;-(

The last submitted patch, 23: provide_a_custom_diff-2433099-23.patch, failed testing.

jeroen.b’s picture

Status: Needs review » Needs work

The last submitted patch, 26: paragraphs_2433099_diff_26.patch, failed testing.

The last submitted patch, 23: provide_a_custom_diff-2433099-23.patch, failed testing.

The last submitted patch, 23: provide_a_custom_diff-2433099-23.patch, failed testing.

jeroen.b’s picture

@miro_dietiker, seems like the dependency is working now?

[1] => Array
                        (
                            [repository] => Array
                                (
                                    [type] => git
                                    [url] => git://git.drupal.org/project/diff.git
                                )

                            [vcs_identifier] => 8.x-1.x
                        )
miro_dietiker’s picture

Cool! Now time to fix and improve.

LKS90’s picture

StatusFileSize
new35.65 KB

Locally the tests pass, and the revisions are correctly shown. Only one slight issue which might not be related to paragraphs: Under the revisions tab the operations look rather strange, some radio buttons are there which mess up the whole formatting, plus some empty padding between the two operations columns. I don't know where the revisions page is built. A screenshot of the weird formatting on /node/{ID}/revisions.

The last submitted patch, 23: provide_a_custom_diff-2433099-23.patch, failed testing.

LKS90’s picture

Rebased the patch #23.

LKS90’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 50: provide_a_custom_diff-rebase-2433099-50.patch, failed testing.

LKS90’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new31.84 KB

What are you doing, testbot?

Status: Needs review » Needs work

The last submitted patch, 50: provide_a_custom_diff-rebase-2433099-50.patch, failed testing.

LKS90’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new44.84 KB
new10.07 KB
new659 bytes

Reproduced the issue on simplytest.me:

Probably a missing dependency. Here is a patch to try out.

Status: Needs review » Needs work

The last submitted patch, 56: provide_a_custom_diff-2433099-56.patch, failed testing.

miro_dietiker’s picture

If you look into the dependencies of the testbot run, you can see it has:
diff, entity_reference_revisions, paragraphs

LKS90’s picture

Status: Needs work » Needs review
StatusFileSize
new287 bytes
new10.04 KB

Thanks to miro_dietiker we found the cause for the test fails: Missing capitalisation of one folder name (diff -> DIff). Now the plugin should be found on the linux test bot as well.

berdir’s picture

  1. index 0000000..d17778a
    --- /dev/null
    
    --- /dev/null
    +++ b/src/Plugin/Diff/EntityReferenceRevisionsFIeldBuilder.php
    
    +++ b/src/Plugin/Diff/EntityReferenceRevisionsFIeldBuilder.php
    @@ -0,0 +1,47 @@
    
    @@ -0,0 +1,47 @@
    +<?php
    +
    +/**
    + * @file
    + * Contains \Drupal\paragraphs\Plugin\Diff\EntityReferenceRevisionsFieldBuilder
    

    There's still a case mismatch here (FIeld)

  2. +++ b/src/Plugin/Diff/EntityReferenceRevisionsFIeldBuilder.php
    @@ -0,0 +1,47 @@
    +    // Every item from $field_items is of type FieldItemInterface.
    +    foreach ($field_items as $field_key => $field_item) {
    

    The use @var to document that, so that phpstorm actually understands it :)

  3. +++ b/src/Plugin/Diff/EntityReferenceRevisionsFIeldBuilder.php
    @@ -0,0 +1,47 @@
    +        $parsed_text = $this->entityParser->parseEntity($field_item->entity);
    +        if (is_array($parsed_text)) {
    +          foreach ($parsed_text as $field_id => $field) {
    +            foreach ($field as $id => $text) {
    +              $result_text[$item_counter + $id] = $text[0];
    +            }
    +            $item_counter = $id + 1;
    

    The problem is that this is kind of paragraph specific or to be more specific, inline entity specific. So we should name the class and plugin in a way that makes that clear.. something like "Entity Reference Revisions Inline Diff" or so.

    Or maybe we should actually just name it Paragraphs Diff or something since it's in this module, otherwise we'd need to move it to that?

  4. +++ b/src/Tests/ParagraphsAdministrationTest.php
    @@ -33,6 +33,8 @@ class ParagraphsAdministrationTest extends WebTestBase {
         'block',
    +    'diff',
    +    'diff_test',
       );
    

    Those shouldn't be needed anymore.

  5. +++ b/src/Tests/ParagraphsAdministrationTest.php
    @@ -129,29 +132,27 @@ class ParagraphsAdministrationTest extends WebTestBase {
       public function testParagraphsCreation() {
         $admin_user = $this->drupalCreateUser(array(
    -      'administer site configuration',
    -      'administer nodes',
    -      'create article content',
    -      'create paragraphs content',
    -      'administer content types',
    -      'administer node fields',
    -      'administer node display',
    -      'administer paragraphs types',
    -      'administer paragraph fields',
    -      'administer paragraph display',
    -      'administer paragraph form display',
    -      'administer node form display',
    -      'edit any article content',
    -      'delete any article content'
    -    ));
    +        'administer site configuration',
    +        'administer nodes',
    +        'create article content',
    

    Unrelated change, let's remove all changes in this file.

  6. +++ b/src/Tests/ParagraphsDiffTest.php
    @@ -0,0 +1,175 @@
    +class ParagraphsDiffTest extends WebTestBase {
    

    Would it make sense to use the demo module for the test, and automatically configure it in there? The demo module would then create a paragraph node with revisions and the test could be very, very simple.

miro_dietiker’s picture

The demo module does much more than what is needed for setup for the diff test and i fear this makes things slow..?

berdir’s picture

It does much more, but it does so through the API. I'd expect that actually isn't much slower than the current test which has a lot of UI interaction.

LKS90’s picture

Here is an updated version which uses the paragraphs_demo module. The other feedback should be implemented as well (file renaming, adding comment for @var, removing unrelated changes).

Status: Needs review » Needs work

The last submitted patch, 63: provide_a_custom_diff-2433099-63.patch, failed testing.

Status: Needs work » Needs review
LKS90’s picture

StatusFileSize
new5.8 KB

The demo is committed now, here is a rebased version of the patch.

Status: Needs review » Needs work

The last submitted patch, 66: provide_a_custom_diff-2433099-66.patch, failed testing.

LKS90’s picture

Status: Needs work » Postponed

I'll set it on postponed for now, waiting for #2540556: Translated paragraphs is not displayed in the correct translation to be fixed before I expand the tests.

I can also open a follow up to expand the tests to cover translated paragraphs diffs in case someone wants to commit this patch.

jeroen.b’s picture

Status: Postponed » Needs work

Status: Needs work » Needs review
jeroen.b’s picture

Status: Needs review » Needs work
StatusFileSize
new25.12 KB

This patch does not work for me. When applied, the diff is empty. See attachment.

jeroen.b’s picture

Hmm, I should probably configure it on admin/config/content/diff/fields first :) But that form currently doesn't save for me...

LKS90’s picture

Status: Needs work » Postponed

Yep, diff needs a patch first. I can't change any options (with a blank install of d8 and diff). I created an issue #2601180: Field settings are not changed on saving and postpone this one (again... :D).

jeroen.b’s picture

jeroen.b’s picture

Status: Postponed » Needs work
miro_dietiker’s picture

EDIT: sorry, wrong issue ;-!

edurenye’s picture

Status: Needs work » Needs review
StatusFileSize
new5.69 KB
new2.23 KB

Rebased, did some cleanup and fixed a failing test.
I reviewed the work and the tests and seems enough covered for now.

Status: Needs review » Needs work

The last submitted patch, 77: provide_a_custom_diff-2433099-77.patch, failed testing.

The last submitted patch, 77: provide_a_custom_diff-2433099-77.patch, failed testing.

The last submitted patch, 77: provide_a_custom_diff-2433099-77.patch, failed testing.

edurenye’s picture

Status: Needs work » Needs review
StatusFileSize
new5.69 KB
new1.59 KB

Ups, I deleted to much.
Now should be fine.

miro_dietiker’s picture

Priority: Normal » Major
Status: Needs review » Needs work

Would be great to have Diff support for Paragraphs in stable.

+++ b/src/Plugin/Diff/ParagraphsFieldDiffBuilder.php
@@ -0,0 +1,44 @@
+class ParagraphsFieldDiffBuilder extends FieldDiffBuilderBase {

But i think we can make it into entity reference revisions, since there is no paragraphs specific code.

See also this discussion in diff module: #2649138: Recursive entity_reference diffs with inline_entity_form and entity_reference_revisions

  1. +++ b/src/Plugin/Diff/ParagraphsFieldDiffBuilder.php
    @@ -0,0 +1,44 @@
    +        $parsed_text = $this->entityParser->parseEntity($field_item->entity);
    

    I think we should check if entity is populated for safety (see recent inconsistency issues).

  2. +++ b/src/Tests/ParagraphsDiffTest.php
    @@ -0,0 +1,129 @@
    +class ParagraphsDiffTest extends WebTestBase {
    ...
    +    'paragraphs_demo',
    

    Hm, rewrite it on top of our composite test entity type?

miro_dietiker’s picture

In the generic diff issue i found a reference to a generic implementation:
https://github.com/vilepickle/diff/blob/entity-reference-revisions-suppo...
We should consider that and figure out what is the best mix. :-)

miro_dietiker’s picture

Project: Paragraphs » Entity Reference Revisions

Discussed, decided. Will be provided by ERR. :-)

johnchque’s picture

Assigned: Unassigned » johnchque

Shouldn't have too many changes.

johnchque’s picture

StatusFileSize
new1.56 KB

Added a working version for testing, tested manually but still need to write tests.

johnchque’s picture

Status: Needs work » Needs review
johnchque’s picture

StatusFileSize
new37.47 KB

Screenshot about a manual test.

miro_dietiker’s picture

Issue tags: +Needs tests

Yeah that's possibly the best thing we can do.

To annotate references with structure (resolved reference fields as [sub-]labels) we would need a total replacement of the NodeRevisionController and more because the field handlers can only return change lines and it is impossible to attach structure. That's much unfortunate for complex composite relationships and references. Field label less diffs can easily be confusing. Unsure where to create the issues to cover this.
Created followup in diff module #2711595: Allow diff providers to attach sub-labels

And eagerly waiting for tests. ;-)

johnchque’s picture

Added tests. :)

Status: Needs review » Needs work

The last submitted patch, 90: provide_a_custom_diff-2433099-90.patch, failed testing.

johnchque’s picture

Status: Needs work » Needs review
StatusFileSize
new5.69 KB
new4.18 KB

Sorry it seems we need to add the test dependencies. Also improved the code a bit, fixed comments.

Status: Needs review » Needs work

The last submitted patch, 92: provide_a_custom_diff-2433099-92.patch, failed testing.

johnchque’s picture

Status: Needs work » Needs review
StatusFileSize
new367 bytes

This should go first right? :)

johnchque’s picture

And the patch without the dependency.

Status: Needs review » Needs work

The last submitted patch, 95: provide_a_custom_diff-2433099-95.patch, failed testing.

miro_dietiker’s picture

Status: Needs work » Needs review

Committed the test dependency.

miro_dietiker’s picture

Status: Needs review » Fixed
Issue tags: -Needs tests

Yeah nice and committed.

I still think diff does something wrong here. If we provide a diff builder for our own field, it should be selected out of the box.
Please create a diff followup for this.

Status: Fixed » Closed (fixed)

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

johnchque’s picture

Followup will be covered here; #2708601: Allow per-field diff configuration