Problem/Motivation

The Unified fields got line numbers.

The Split fields still doesn't have.

Proposed resolution

Add line numbers to the Split fields for Raw filter, and hide them for Strip tags filter similar to #2802835: Hide line numbers when stripping markup?.

User interface changes

"Split fields" before changes (both Raw/Strip tags filter modes):

Line numbers added for "Split fields" "Raw" filter:

Line numbers hidden for "Split fields" "Strip tags" filter:

CommentFileSizeAuthor
#54 split_striptags_after.png42.15 KBtduong
#54 split_raw_after.png41.43 KBtduong
#54 split_raw_striptags_before.png40.1 KBtduong
#53 Screenshot from 2016-09-29 09-27-19.png37.99 KBdrobnjak
#53 interdiff-2802829-48-53.txt579 bytesdrobnjak
#53 edit_add_line_numbers-2802829-53.patch7.3 KBdrobnjak
#51 Screen Shot 2016-09-28 at 15.44.56.png19.72 KBtduong
#51 Screen Shot 2016-09-28 at 15.44.32.png19.76 KBtduong
#48 interdiff-2802829-45-48.txt1.21 KBdrobnjak
#48 edit_add_line_numbers-2802829-48.patch7.3 KBdrobnjak
#45 interdiff-2802829-42-45.txt839 bytesdrobnjak
#45 edit_add_line_numbers-2802829-45.patch7.11 KBdrobnjak
#43 interdiff-2802829-35-42.txt4.73 KBdrobnjak
#43 edit_add_line_numbers-2802829-42.patch6.99 KBdrobnjak
#35 interdiff-2802829-33-35.txt4.99 KBdrobnjak
#35 edit_add_line_numbers-2802829-35.patch8.96 KBdrobnjak
#35 Screenshot from 2016-09-28 14-44-52.png29.98 KBdrobnjak
#33 edit_add_line_numbers-2802829-33.patch9.16 KBdrobnjak
#33 interdiff-2802829-31-33.txt562 bytesdrobnjak
#31 interdiff-2802829-29-31.txt860 bytesdrobnjak
#31 edit_add_line_numbers-2802829-31.patch9.17 KBdrobnjak
#29 edit_add_line_numbers-2802829-29.patch9.22 KBdrobnjak
#29 interdiff-2802829-27-29.txt2.64 KBdrobnjak
#27 interdiff-2802829-24-27.txt2.15 KBdrobnjak
#27 edit_add_line_numbers-2802829-27.patch9.61 KBdrobnjak
#24 interdiff-2802829-22-24.txt4.16 KBdrobnjak
#24 edit_add_line_numbers-2802829-24.patch9.41 KBdrobnjak
#22 interdiff-2802829-19-22.txt9.09 KBdrobnjak
#22 edit_add_line_numbers-2802829-22.patch12.72 KBdrobnjak
#19 interdiff-2802829-13-19.txt727 bytesdrobnjak
#19 edit_add_line_numbers-2802829-19.patch3.8 KBdrobnjak
#13 interdiff-2802829-10-13.txt1.55 KBdrobnjak
#13 edit_add_line_numbers-2802829-13.patch4.7 KBdrobnjak
#13 Screenshot from 2016-09-23 11-47-33.png35 KBdrobnjak
#10 Screenshot from 2016-09-22 10-21-07.png56.59 KBdrobnjak
#10 interdiff-2802829-3-10.txt2.64 KBdrobnjak
#10 edit_add_line_numbers-2802829-10.patch3.77 KBdrobnjak
#7 Screenshot from 2016-09-21 11-08-59.png51.68 KBdrobnjak
#3 edit_add_line_numbers-2802829-3.patch3.52 KBdrobnjak
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

miro_dietiker created an issue. See original summary.

drobnjak’s picture

Assigned: Unassigned » drobnjak
drobnjak’s picture

drobnjak’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 3: edit_add_line_numbers-2802829-3.patch, failed testing.

toncic’s picture

+++ b/src/Plugin/diff/Layout/SplitFieldsDiffLayout.php
@@ -142,13 +142,54 @@ class SplitFieldsDiffLayout extends DiffLayoutBase {
+            'class' => [isset($field_diff_rows[$key][0]['class']) ? $field_diff_rows[$key][0]['class'] : NULL, $field_diff_rows[$key][1]['class']]

You should add comma after last element in array. https://www.drupal.org/docs/develop/standards/coding-standards#array

+++ b/src/Plugin/diff/Layout/SplitFieldsDiffLayout.php
@@ -142,13 +142,54 @@ class SplitFieldsDiffLayout extends DiffLayoutBase {
+            'class' => [isset($field_diff_rows[$key][2]['class']) ? $field_diff_rows[$key][2]['class'] : NULL, $field_diff_rows[$key][3]['class']]

Here the same.

+++ b/src/Plugin/diff/Layout/SplitFieldsDiffLayout.php
@@ -142,13 +142,54 @@ class SplitFieldsDiffLayout extends DiffLayoutBase {
+

You have one extra line here.

drobnjak’s picture

Providing screenshot for patch-3

johnchque’s picture

+++ b/src/Plugin/diff/Layout/SplitFieldsDiffLayout.php
@@ -142,13 +142,54 @@ class SplitFieldsDiffLayout extends DiffLayoutBase {
+      //CUSTOM
...
+      //END OF CUSTOM

Please remove this.

Besides that is better to test manually too.

miro_dietiker’s picture

+++ b/src/Plugin/diff/Layout/SplitFieldsDiffLayout.php
@@ -142,13 +142,54 @@ class SplitFieldsDiffLayout extends DiffLayoutBase {
+        $row_count_right++;
+        $row_count_left++;

You are counting up in parallel, unconditionally for left and right?

We need a test that is following a more real multiline example, such as:
- Have a text field with 5 lines
- Remove the 1st and 4rth lines, plus replace the 3rd row with some new line, possibly even add multiple lines there.

And then assert the line numbers.

drobnjak’s picture

Status: Needs work » Needs review
FileSize
3.77 KB
2.64 KB
56.59 KB

There are conditional statements and I tested it as it is suggested in comment #9.
I also removed custom code comments as suggested in comment #8.
There is a screenshot provided.

Status: Needs review » Needs work

The last submitted patch, 10: edit_add_line_numbers-2802829-10.patch, failed testing.

miro_dietiker’s picture

Hm, that's interesting. I was expecting a different output, but i kinda can see that this one isn't necessarily wrong...

But the example is polluted with the <p> and the </p> tag that makes every line changed.
I really wanted to have these lines unchanged.
To solve the p problem, please add an empty / placeholder line first and at the end.

Also what is confusing though is, why the line after the +/- has no line number.

drobnjak’s picture

I have provided another example which can pull maybe potential issues.
This example is created with using "enter" instead of "shift+enter" and creating whitelines between the rows. When the whiteline is removed, layout considers it as a change. Now all of the lines that have data have line numbers, like in Unified fields layout.

drobnjak’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 13: edit_add_line_numbers-2802829-13.patch, failed testing.

toncic’s picture

+++ b/src/Plugin/diff/Layout/SplitFieldsDiffLayout.php
@@ -142,13 +142,56 @@ class SplitFieldsDiffLayout extends DiffLayoutBase {
+        if(trim($field_diff_rows[$key][3]['data']['#markup']) != "") {

Space between "if" and "(".

+++ b/src/Plugin/diff/Layout/SplitFieldsDiffLayout.php
@@ -142,13 +142,56 @@ class SplitFieldsDiffLayout extends DiffLayoutBase {
+        if(trim($field_diff_rows[$key][3]['data']['#markup']) != "") {

Here the same.

miro_dietiker’s picture

Yeah the diff now looks much more like expected.

Lots of tests failing. :-)

miro_dietiker’s picture

+++ b/src/Form/RevisionOverviewForm.php
@@ -153,8 +153,10 @@ class RevisionOverviewForm extends FormBase {
-    $table_header = [];
-    $table_header['revision'] = $this->t('Revision');
+    $table_header = array(
+      'revision' => $this->t('Revision'),
+      'operations' => $this->t('Operations'),
+    );

@@ -163,7 +165,6 @@ class RevisionOverviewForm extends FormBase {
-    $table_header['operations'] = $this->t('Operations');

Unrelated revert of some other recently committed issue. Please always pull / merge / rebase your branch.

drobnjak’s picture

drobnjak’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 19: edit_add_line_numbers-2802829-19.patch, failed testing.

drobnjak’s picture

Status: Needs work » Needs review
FileSize
12.72 KB
9.09 KB

Test changes that should follow the changes of the Split fields layout. Together with changes from the patch https://www.drupal.org/node/2800155#comment-11659699 to remove additional errors "Illegal string offset".

Status: Needs review » Needs work

The last submitted patch, 22: edit_add_line_numbers-2802829-22.patch, failed testing.

drobnjak’s picture

Reversed changes from https://www.drupal.org/node/2800155#comment-11659699 issue that were applied by mistake.
Changes made to the Split fields to evade "Illegal string offset errors"

drobnjak’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 24: edit_add_line_numbers-2802829-24.patch, failed testing.

drobnjak’s picture

Status: Needs work » Needs review
FileSize
9.61 KB
2.15 KB

Fixed "Illegal string offset errors" completely

Status: Needs review » Needs work

The last submitted patch, 27: edit_add_line_numbers-2802829-27.patch, failed testing.

drobnjak’s picture

Status: Needs work » Needs review
FileSize
2.64 KB
9.22 KB

Status: Needs review » Needs work

The last submitted patch, 29: edit_add_line_numbers-2802829-29.patch, failed testing.

drobnjak’s picture

Status: Needs work » Needs review
FileSize
9.17 KB
860 bytes
johnchque’s picture

Status: Needs review » Needs work
+++ b/src/Controller/PluginRevisionController.php
@@ -281,7 +281,7 @@ class PluginRevisionController extends ControllerBase {
-
+  ¶

unrelated change. :)

drobnjak’s picture

Status: Needs work » Needs review
FileSize
562 bytes
9.16 KB
miro_dietiker’s picture

Status: Needs review » Needs work
Related issues: +#2802835: Hide line numbers when stripping markup?

Please also consider similarly to only display the line numbers in raw mode like #2802835: Hide line numbers when stripping markup?

drobnjak’s picture

Feature added, numbers are removed together with columns on "strip_tags".
I am working on test fixes.

drobnjak’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 35: edit_add_line_numbers-2802829-35.patch, failed testing.

johnchque’s picture

+++ b/src/Tests/DiffRevisionTest.php
@@ -121,10 +121,8 @@ class DiffRevisionTest extends DiffTestBase {
-    $this->assertEqual((string) (($diff_row[1]->span)), '1');
...
-    $this->assertEqual((string) (($diff_row[3]->span)), '2');

We need these lines. :)

johnchque’s picture

+++ b/src/DiffLayoutManager.php
@@ -87,7 +87,7 @@ class DiffLayoutManager extends DefaultPluginManager {
-   *
+   *git sta

unrelated change. :)

johnchque’s picture

+++ b/src/Tests/DiffRevisionTest.php
@@ -121,10 +121,8 @@ class DiffRevisionTest extends DiffTestBase {
-    $this->assertEqual((string) (($diff_row[1]->span)), '1');
...
-    $this->assertEqual((string) (($diff_row[2])), '+');
-    $this->assertEqual((string) (($diff_row[3]->span)), '2');

@@ -240,12 +238,12 @@ class DiffRevisionTest extends DiffTestBase {
-    $this->assertEqual(htmlspecialchars_decode(strip_tags($diff_row[3]->asXML())), 'new body');
...
-    $this->assertEqual(htmlspecialchars_decode(strip_tags($diff_row[3]->asXML())), 'newer body');

This lines should remain the same. :)

tduong’s picture

I was taking over this, forgot to assign the issue to myself and have seen later that a patch has been already uploaded...

Then I'll post some feedback/considerations:

  1. +++ b/src/Plugin/diff/Layout/SplitFieldsDiffLayout.php
    @@ -142,13 +142,67 @@ class SplitFieldsDiffLayout extends DiffLayoutBase {
    +        if(isset($field_diff_rows[$key][1]['data']) && trim($field_diff_rows[$key][1]['data']['#markup']) != '') {
    ...
    +        if(isset($field_diff_rows[$key][3]['data']) && trim($field_diff_rows[$key][3]['data']['#markup']) != '') {
    

    I suggest you to change the settings in phpStorm to avoid this if(.

  2. +++ b/src/Plugin/diff/Layout/SplitFieldsDiffLayout.php
    @@ -142,13 +142,67 @@ class SplitFieldsDiffLayout extends DiffLayoutBase {
    +            'class' => ['diff-line-number', isset($field_diff_rows[$key][1]['data']) ? $field_diff_rows[$key][1]['class'] : NULL],
    

    Compared with the code in UnifiedFieldsDiffLayout, is this kind of check (and more in this code) really needed, or is the code in the other file not safe and need to be improved?

  3. +++ b/src/Plugin/diff/Layout/SplitFieldsDiffLayout.php
    @@ -142,13 +142,67 @@ class SplitFieldsDiffLayout extends DiffLayoutBase {
    +        if ($active_filter == 'strip_tags') {
    ...
    +    if ($active_filter == 'strip_tags') {
    

    To make it more similar to the other code, you might need to add $raw_active = $active_filter == 'raw'; before the $fields foreach loop and replace $active_filter == 'strip_tags' with !$raw_active.

  4. +++ b/src/Plugin/diff/Layout/SplitFieldsDiffLayout.php
    @@ -142,13 +142,67 @@ class SplitFieldsDiffLayout extends DiffLayoutBase {
    +          $final_diff[$row_counter] = [$final_diff[$row_counter][1],
    +            $final_diff[$row_counter][2], $final_diff[$row_counter][4],
    +            $final_diff[$row_counter][5]];
    

    Format this better, like:

    $array = [
        $item1,
        $item2,
        $item3,
    ];
  5. +++ b/src/Plugin/diff/Layout/SplitFieldsDiffLayout.php
    @@ -142,13 +142,67 @@ class SplitFieldsDiffLayout extends DiffLayoutBase {
    +      }
           // Add the field label to the table only if there are changes to that field.
    

    Add a new line here to separate the code (readability).

  6. +++ b/src/Plugin/diff/Layout/SplitFieldsDiffLayout.php
    @@ -181,11 +235,11 @@ class SplitFieldsDiffLayout extends DiffLayoutBase {
    +      'colspan' => 4,
    

    Is it allowed to set this (as 3) differently than the second colspan or must they have the same value ?

Otherwise UI looks good!

johnchque’s picture

About 41.2 yes, those checks are needed otherwise we will get some php warnings.

drobnjak’s picture

Status: Needs work » Needs review
FileSize
6.99 KB
4.73 KB

Applied changes from comments 38-41. Check in the 41. 2) is to avoid the class offset errors in tests.

johnchque’s picture

Status: Needs review » Needs work
+++ b/src/Tests/DiffRevisionTest.php
@@ -97,12 +97,12 @@ class DiffRevisionTest extends DiffTestBase {
-    $this->assertEqual((string) (($diff_row[1]->span)), '1');
...
-    $this->assertEqual((string) (($diff_row[3]->span)), '2');

Almost! We don't want to remove this. :)

drobnjak’s picture

Status: Needs work » Needs review
FileSize
7.11 KB
839 bytes
johnchque’s picture

Status: Needs review » Reviewed & tested by the community

Looks really nice now. :)

tduong’s picture

Status: Reviewed & tested by the community » Needs work

Some last nitpicks:

  1. +++ b/src/Plugin/diff/Layout/SplitFieldsDiffLayout.php
    @@ -115,12 +115,13 @@ class SplitFieldsDiffLayout extends DiffLayoutBase {
    +      $raw_active = $active_filter == 'raw';
    

    This should be defined outside foreach ($fields as $field).

    The code in the other file needs improvement as well, need a followup to improve/cleanup that code.

  2. +++ b/src/Plugin/diff/Layout/SplitFieldsDiffLayout.php
    @@ -142,13 +143,70 @@ class SplitFieldsDiffLayout extends DiffLayoutBase {
    +        ];
    +        if (!$raw_active) {
    

    New line (readability).

  3. +++ b/src/Plugin/diff/Layout/SplitFieldsDiffLayout.php
    @@ -142,13 +143,70 @@ class SplitFieldsDiffLayout extends DiffLayoutBase {
    +            $final_diff[$row_counter][5]];
    

    Add a come after the last element and ]; in a new line (coding standard).

Then is fine :)

drobnjak’s picture

Status: Needs work » Needs review
FileSize
7.3 KB
1.21 KB
johnchque’s picture

Status: Needs review » Reviewed & tested by the community

Even better now.

tduong’s picture

Agree

tduong’s picture

Oh wait, missed 41.6)
Mind the difference between the following (REV2 header):

Just a small thing, otherwise is ok.

johnchque’s picture

Status: Reviewed & tested by the community » Needs work

True, the colspan should be 3 and not 4. We also need new screenshots after that change.

drobnjak’s picture

Status: Needs work » Needs review
FileSize
7.3 KB
579 bytes
37.99 KB

Header changes

tduong’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
FileSize
40.1 KB
41.43 KB
42.15 KB

Now it's alright! :)
Updated IS with screenshots as well.

miro_dietiker’s picture

Status: Reviewed & tested by the community » Fixed

Yeah commmitted, great.

Again, let me point to the issue about using named columns:
#2785857: Introduce header / row table keys
The cols have numerical references now and they change depending on conditions... That's really bad in case someone wants to alter stuff - there is no clear reference. Also with named references, an unset($row['number_left']) would be enough to delete the left column with number and no crazy number juggling would be needed.

Status: Fixed » Closed (fixed)

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