diff -u b/src/DiffEntityComparison.php b/src/DiffEntityComparison.php --- b/src/DiffEntityComparison.php +++ b/src/DiffEntityComparison.php @@ -270,29 +270,52 @@ public function getRevisionDescription(ContentEntityInterface $revision, ContentEntityInterface $previous_revision = NULL) { $auto_generated = FALSE; $revision_summary = []; + // Check if the revision has a revision log, if not the auto generate it. if ($revision instanceof RevisionLogInterface) { $revision_summary = Xss::filter($revision->getRevisionLogMessage()); - if ($revision_summary == '' && $previous_revision) { + if ($revision_summary == '') { $auto_generated = TRUE; $revision_summary = []; } } - elseif ($previous_revision) { + else{ $auto_generated = TRUE; } if ($auto_generated) { - $left_values = $this->summary($previous_revision); - $right_values = $this->summary($revision); - foreach ($right_values as $key => $value) { - if (isset($left_values[$key]) && $value != $left_values[$key]) { - $revision_summary[] = $value['label']; + // If there is a previous revision, load the values of each and add to the + // summary the ones that have changed. + if ($previous_revision) { + $left_values = $this->summary($previous_revision); + $right_values = $this->summary($revision); + foreach ($right_values as $key => $value) { + // If the field is present in the left entity, compare values, if not + // add it to the summary. Unset the ones already added. + if (isset($left_values[$key])) { + if ($value != $left_values[$key]) { + $revision_summary[] = $value['label']; + } + unset($left_values[$key]); + } + else { + $revision_summary[] = $value['label']; + } + } + // Loop over the left values that remain and add them if not present in + // the right entity. + foreach ($left_values as $key => $value) { + if (!isset($right_values[$key])) { + $revision_summary[] = $value['label']; + } + } + if (count($revision_summary) > 0) { + $revision_summary = 'Changes on: ' . implode(', ', $revision_summary); + } + else { + $revision_summary = 'No changes.'; } - } - if (count($revision_summary) > 0) { - $revision_summary = 'Changes on: ' . implode(', ', $revision_summary); } else { - $revision_summary = 'No changes.'; + $revision_summary = 'Initial revision.'; } } only in patch2: unchanged: --- a/src/Tests/DiffRevisionTest.php +++ b/src/Tests/DiffRevisionTest.php @@ -73,7 +73,7 @@ class DiffRevisionTest extends DiffTestBase { $this->assertEqual(count($rows), 2); // Assert the revision summary. $this->assertUniqueText('Revision 2 comment'); - $this->assertText('No changes.'); + $this->assertText('Initial revision.'); // Compare the revisions in standard mode. $this->drupalPostForm(NULL, NULL, t('Compare'));