diff --git a/src/Plugin/Layout/ClassicDiffLayout.php b/src/Plugin/Layout/ClassicDiffLayout.php index 630cf9f..c750036 100644 --- a/src/Plugin/Layout/ClassicDiffLayout.php +++ b/src/Plugin/Layout/ClassicDiffLayout.php @@ -21,7 +21,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; /** * @DiffLayoutBuilder( * id = "classic_layout", - * label = @Translation("Classic"), + * label = @Translation("Standard"), * ) */ class ClassicDiffLayout extends DiffLayoutBase { @@ -93,41 +93,42 @@ class ClassicDiffLayout extends DiffLayoutBase { public function build(array $build, EntityInterface $left_revision, EntityInterface $right_revision, EntityInterface $entity) { $diff_header = $this->buildTableHeader($left_revision, $right_revision); // Perform comparison only if both entity revisions loaded successfully. - $fields = $this->entityComparison->compareRevisions($left_revision, $right_revision); - // Build the diff rows for each field and append the field rows - // to the table rows. - foreach ($fields as $field) { - $field_label_row = ''; - if (!empty($field['#name'])) { - $field_label_row = array( - 'data' => $this->t('%name', ['%name' => $field['#name']]), - 'colspan' => 4, - 'class' => array('field-name'), - ); - } - $field_diff_rows = $this->entityComparison->getRows( - $field['#states']['raw']['#left'], - $field['#states']['raw']['#right'] + $fields = $this->entityComparison->compareRevisions($left_revision, $right_revision); + // Build the diff rows for each field and append the field rows + // to the table rows. + $diff_rows = []; + foreach ($fields as $field) { + $field_label_row = ''; + if (!empty($field['#name'])) { + $field_label_row = array( + 'data' => $this->t('%name', ['%name' => $field['#name']]), + 'colspan' => 4, + 'class' => array('field-name'), ); + } + $field_diff_rows = $this->entityComparison->getRows( + $field['#states']['raw']['#left'], + $field['#states']['raw']['#right'] + ); - // Add the field label to the table only if there are changes to that field. - if (!empty($field_diff_rows) && !empty($field_label_row)) { - $diff_rows[] = array($field_label_row); - } - - // Add field diff rows to the table rows. - $diff_rows = array_merge($diff_rows, $field_diff_rows); + // Add the field label to the table only if there are changes to that field. + if (!empty($field_diff_rows) && !empty($field_label_row)) { + $diff_rows[] = array($field_label_row); } - $build['diff'] = array( - '#type' => 'table', - '#header' => $diff_header, - '#rows' => $diff_rows, - '#empty' => $this->t('No visible changes'), - '#attributes' => array( - 'class' => array('diff'), - ), - ); + // Add field diff rows to the table rows. + $diff_rows = array_merge($diff_rows, $field_diff_rows); + } + + $build['diff'] = array( + '#type' => 'table', + '#header' => $diff_header, + '#rows' => $diff_rows, + '#empty' => $this->t('No visible changes'), + '#attributes' => array( + 'class' => array('diff'), + ), + ); $build['#attached']['library'][] = 'diff/diff.github'; return $build; @@ -171,7 +172,7 @@ class ClassicDiffLayout extends DiffLayoutBase { protected function buildRevisionLink(EntityInterface $revision) { $entity_type_id = $revision->getEntityTypeId(); if ($revision instanceof EntityRevisionLogInterface || $revision instanceof NodeInterface) { - $revision_log = $this->nonBreakingSpace; + $revision_log = ''; if ($revision instanceof EntityRevisionLogInterface) { $revision_log = Xss::filter($revision->getRevisionLogMessage()); diff --git a/src/Plugin/Layout/MarkdownDiffLayout.php b/src/Plugin/Layout/MarkdownDiffLayout.php index a78f814..799b93d 100644 --- a/src/Plugin/Layout/MarkdownDiffLayout.php +++ b/src/Plugin/Layout/MarkdownDiffLayout.php @@ -93,41 +93,42 @@ class MarkdownDiffLayout extends DiffLayoutBase { public function build(array $build, EntityInterface $left_revision, EntityInterface $right_revision, EntityInterface $entity) { $diff_header = $this->buildTableHeader($left_revision, $right_revision); // Perform comparison only if both entity revisions loaded successfully. - $fields = $this->entityComparison->compareRevisions($left_revision, $right_revision); - // Build the diff rows for each field and append the field rows - // to the table rows. - foreach ($fields as $field) { - $field_label_row = ''; - if (!empty($field['#name'])) { - $field_label_row = array( - 'data' => $this->t('%name', ['%name' => $field['#name']]), - 'colspan' => 4, - 'class' => array('field-name'), - ); - } - $field_diff_rows = $this->entityComparison->getRows( - $field['#states']['raw_plain']['#left'], - $field['#states']['raw_plain']['#right'] + $fields = $this->entityComparison->compareRevisions($left_revision, $right_revision); + // Build the diff rows for each field and append the field rows + // to the table rows. + $diff_rows = []; + foreach ($fields as $field) { + $field_label_row = ''; + if (!empty($field['#name'])) { + $field_label_row = array( + 'data' => $this->t('%name', ['%name' => $field['#name']]), + 'colspan' => 4, + 'class' => array('field-name'), ); + } + $field_diff_rows = $this->entityComparison->getRows( + $field['#states']['raw_plain']['#left'], + $field['#states']['raw_plain']['#right'] + ); - // Add the field label to the table only if there are changes to that field. - if (!empty($field_diff_rows) && !empty($field_label_row)) { - $diff_rows[] = array($field_label_row); - } - - // Add field diff rows to the table rows. - $diff_rows = array_merge($diff_rows, $field_diff_rows); + // Add the field label to the table only if there are changes to that field. + if (!empty($field_diff_rows) && !empty($field_label_row)) { + $diff_rows[] = array($field_label_row); } - $build['diff'] = array( - '#type' => 'table', - '#header' => $diff_header, - '#rows' => $diff_rows, - '#empty' => $this->t('No visible changes'), - '#attributes' => array( - 'class' => array('diff'), - ), - ); + // Add field diff rows to the table rows. + $diff_rows = array_merge($diff_rows, $field_diff_rows); + } + + $build['diff'] = array( + '#type' => 'table', + '#header' => $diff_header, + '#rows' => $diff_rows, + '#empty' => $this->t('No visible changes'), + '#attributes' => array( + 'class' => array('diff'), + ), + ); $build['#attached']['library'][] = 'diff/diff.github'; return $build; @@ -171,7 +172,7 @@ class MarkdownDiffLayout extends DiffLayoutBase { protected function buildRevisionLink(EntityInterface $revision) { $entity_type_id = $revision->getEntityTypeId(); if ($revision instanceof EntityRevisionLogInterface || $revision instanceof NodeInterface) { - $revision_log = $this->nonBreakingSpace; + $revision_log = ''; if ($revision instanceof EntityRevisionLogInterface) { $revision_log = Xss::filter($revision->getRevisionLogMessage()); diff --git a/src/Tests/DiffPluginTest.php b/src/Tests/DiffPluginTest.php index 405c0b6..df78751 100644 --- a/src/Tests/DiffPluginTest.php +++ b/src/Tests/DiffPluginTest.php @@ -221,7 +221,9 @@ class DiffPluginTest extends DiffTestBase { // "changed" field is not displayed since there is no plugin for it. This // should not break the revisions comparison display. $this->assertResponse(200); - $this->assertLink(t('Back to Revision Overview')); + $this->drupalGet('node/' . $node->id()); + // Check the difference between the last two revisions. + $this->clickLink(t('Revisions')); $this->assertLink(t('Standard')); } diff --git a/src/Tests/DiffRevisionTest.php b/src/Tests/DiffRevisionTest.php index aacdcc9..310037c 100644 --- a/src/Tests/DiffRevisionTest.php +++ b/src/Tests/DiffRevisionTest.php @@ -71,7 +71,7 @@ class DiffRevisionTest extends DiffTestBase { $this->assertText('Body'); $rows = $this->xpath('//tbody/tr'); $head = $this->xpath('//thead/tr'); - $diff_row = $rows[3]->td; + $diff_row = $rows[1]->td; $comment = $head[0]->th[1]; // Assert the revision comment. $this->assertEqual((string) $comment, 'Revision 2 comment'); @@ -86,7 +86,7 @@ class DiffRevisionTest extends DiffTestBase { // Compare the revisions in markdown mode. $this->clickLink('Markdown'); $rows = $this->xpath('//tbody/tr'); - $diff_row = $rows[3]->td; + $diff_row = $rows[1]->td; // Assert changes made to the body, text 1 changed to 2. $this->assertEqual((string) ($diff_row[0]), '-'); $this->assertEqual((string) (($diff_row[1]->span)), '1'); @@ -95,8 +95,8 @@ class DiffRevisionTest extends DiffTestBase { $this->assertEqual((string) (($diff_row[3]->span)), '2'); $this->assertEqual(htmlspecialchars_decode((strip_tags($diff_row[3]->asXML()))), 'Revision 2'); - // Go back to revision overview. - $this->clickLink(t('Back to Revision Overview')); + $this->drupalGet('node/' . $node->id()); + $this->clickLink(t('Revisions')); // Revert the revision, confirm. $this->clickLink(t('Revert')); $this->drupalPostForm(NULL, NULL, t('Revert'));