diff --git a/css/diff.general.css b/css/diff.general.css index dc6e2ef..930bf69 100644 --- a/css/diff.general.css +++ b/css/diff.general.css @@ -7,4 +7,12 @@ } #diffadminplugins .messages { margin-bottom: 0.5em; -} \ No newline at end of file +} +.diff-filter { + display: inline-block; +} +.navigation-link { + text-align: center; + width: 50%; + display: inline-block; +} diff --git a/diff.routing.yml b/diff.routing.yml index c858606..a493bbf 100644 --- a/diff.routing.yml +++ b/diff.routing.yml @@ -3,7 +3,7 @@ diff.revisions_diff: defaults: _controller: '\Drupal\diff\Controller\NodeRevisionController::compareNodeRevisions' _title: Diff General Settings - filter: 'raw' + filter: 'classic_layout' requirements: _access_node_revision: 'view' options: diff --git a/src/Controller/PluginRevisionController.php b/src/Controller/PluginRevisionController.php index d212e17..061c223 100644 --- a/src/Controller/PluginRevisionController.php +++ b/src/Controller/PluginRevisionController.php @@ -2,7 +2,6 @@ namespace Drupal\diff\Controller; -use Drupal\Core\Datetime\DateFormatter; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Routing\RouteMatchInterface; @@ -42,7 +41,7 @@ class PluginRevisionController extends ControllerBase { * @param DiffLayoutManager $diff_layout_manager * DiffLayoutManager service. */ - public function __construct(DateFormatter $date, DiffEntityComparison $entity_comparison, DiffLayoutManager $diff_layout_manager) { + public function __construct(DiffEntityComparison $entity_comparison, DiffLayoutManager $diff_layout_manager) { $this->config = $this->config('diff.settings'); $this->diffLayoutManager = $diff_layout_manager; $this->entityComparison = $entity_comparison; @@ -53,7 +52,6 @@ class PluginRevisionController extends ControllerBase { */ public static function create(ContainerInterface $container) { return new static( - $container->get('date.formatter'), $container->get('diff.entity_comparison'), $container->get('plugin.manager.diff.layout') ); @@ -69,7 +67,7 @@ class PluginRevisionController extends ControllerBase { * * @return array */ - protected function getVids(EntityStorageInterface $storage, $entity_id) { + public function getVids(EntityStorageInterface $storage, $entity_id) { $result = $storage->getQuery() ->allRevisions() ->condition($storage->getEntityType()->getKey('id'), $entity_id) @@ -98,19 +96,48 @@ class PluginRevisionController extends ControllerBase { public function compareEntityRevisions(RouteMatchInterface $route_match, EntityInterface $left_revision, EntityInterface $right_revision, $filter) { $entity_type_id = $left_revision->getEntityTypeId(); $entity = $route_match->getParameter($entity_type_id); + + $entity_type_id = $entity->getEntityTypeId(); + $storage = $this->entityTypeManager->getStorage($entity_type_id); + // Get language from the entity context. + $langcode = $entity->language()->getId(); + + // Get left and right revision in current language. + $left_revision = $left_revision->getTranslation($langcode); + $right_revision = $right_revision->getTranslation($langcode); + + $vids = []; + // Filter revisions of current translation and where the translation is + // affected. + foreach ($this->getVids($storage, $entity->id()) as $vid) { + $revision = $storage->loadRevision($vid); + if ($revision->hasTranslation($langcode) && $revision->getTranslation($langcode)->isRevisionTranslationAffected()) { + $vids[] = $vid; + } + } + $build = array( '#title' => $this->t('Changes to %title', ['%title' => $entity->label()]), ); - $build['filter'] = $this->buildMarkdownNavigation($entity, $left_revision->getRevisionId(), $right_revision->getRevisionId(), $filter); + // Build the layout filter. + $build['diff_layout'] = [ + '#type' => 'item', + '#title' => $this->t('Layout'), + ]; + $build['diff_layout']['filter'] = $this->buildMarkdownNavigation($entity, $left_revision->getRevisionId(), $right_revision->getRevisionId(), $filter); + + // Build the navigation links. + $build['diff_navigation'] = $this->buildRevisionsNavigation($entity, $vids, $left_revision->getRevisionId(), $right_revision->getRevisionId()); // Perform comparison only if both entity revisions loaded successfully. if ($left_revision != FALSE && $right_revision != FALSE) { // Build the diff comparison with the plugin. - $plugin = $this->diffLayoutManager->createInstance('classic_diff_layout'); - $build = $plugin->build($build, $left_revision, $right_revision, $route_match); + $plugin = $this->diffLayoutManager->createInstance($filter); + $build = $plugin->build($build, $left_revision, $right_revision, $entity); } + $build['#attached']['library'][] = 'diff/diff.general'; return $build; } @@ -126,6 +153,11 @@ class PluginRevisionController extends ControllerBase { ); } + // Set as the first element the current filter. + $filter = $links[$active_filter]; + unset($links[$active_filter]); + array_unshift($links, $filter); + $filter = [ '#type' => 'operations', '#links' => $links, @@ -136,6 +168,52 @@ class PluginRevisionController extends ControllerBase { return $filter; } + protected function buildRevisionsNavigation(EntityInterface $entity, $vids, $left_vid, $right_vid) { + $revisions_count = count($vids); + // If there are only 2 revision return an empty row. + if ($revisions_count == 2) { + return []; + } + else { + $left_link = $right_link = ''; + $element['diff_navigation'] = [ + '#type' => 'item', + '#title' => $this->t('Navigation'), + ]; + $i = 0; + // Find the previous revision. + while ($left_vid > $vids[$i]) { + $i += 1; + } + if ($i != 0) { + // build the left link. + $left_link = $this->l($this->t('< Previous difference'), $this->diffRoute($entity, $vids[$i - 1], $left_vid)); + } + $element['diff_navigation']['left'] = [ + '#type' => 'markup', + '#markup' => $left_link, + '#prefix' => '', + '#suffix' => '', + ]; + // Find the next revision. + $i = 0; + while ($i < $revisions_count && $right_vid >= $vids[$i]) { + $i += 1; + } + if ($revisions_count != $i && $vids[$i - 1] != $vids[$revisions_count - 1]) { + // Build the right link. + $right_link = $this->l($this->t('Next difference >'), $this->diffRoute($entity, $right_vid, $vids[$i])); + } + $element['diff_navigation']['right'] = [ + '#type' => 'markup', + '#markup' => $right_link, + '#prefix' => '', + '#suffix' => '', + ]; + return $element; + } + } + /** * Creates an url object for diff. * diff --git a/src/DiffLayoutBase.php b/src/DiffLayoutBase.php index 6c38cfd..4f9f9f3 100644 --- a/src/DiffLayoutBase.php +++ b/src/DiffLayoutBase.php @@ -56,7 +56,6 @@ abstract class DiffLayoutBase extends PluginBase implements DiffLayoutInterface, $this->entityTypeManager = $entity_type_manager; $this->entityParser = $entityParser; parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->configuration += $this->defaultConfiguration(); } @@ -74,14 +73,23 @@ abstract class DiffLayoutBase extends PluginBase implements DiffLayoutInterface, ); } + /** + * {@inheritdoc} + */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { // TODO: Implement buildConfigurationForm() method. } + /** + * {@inheritdoc} + */ public function validateConfigurationForm(array &$form, FormStateInterface $form_state) { // TODO: Implement validateConfigurationForm() method. } + /** + * {@inheritdoc} + */ public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { // TODO: Implement submitConfigurationForm() method. } @@ -90,9 +98,7 @@ abstract class DiffLayoutBase extends PluginBase implements DiffLayoutInterface, * {@inheritdoc} */ public function defaultConfiguration() { - return array( - - ); + return []; } /** @@ -113,6 +119,6 @@ abstract class DiffLayoutBase extends PluginBase implements DiffLayoutInterface, * {@inheritdoc} */ public function calculateDependencies() { - return array(); + return []; } } diff --git a/src/DiffLayoutInterface.php b/src/DiffLayoutInterface.php index 635a141..b3393e9 100644 --- a/src/DiffLayoutInterface.php +++ b/src/DiffLayoutInterface.php @@ -33,7 +33,7 @@ interface DiffLayoutInterface extends PluginFormInterface, ConfigurablePluginInt * The left revision. * @param \Drupal\Core\Entity\EntityInterface $right_revision * The right revision. - * @param \Drupal\Core\Routing\RouteMatchInterface $route_match + * @param \Drupal\Core\Entity\EntityInterface $entity * The route match. * * @return mixed @@ -41,5 +41,5 @@ interface DiffLayoutInterface extends PluginFormInterface, ConfigurablePluginInt * means that a field is either empty or no properties need to be compared * for that field. */ - public function build(array $build, EntityInterface $left_revision, EntityInterface $right_revision, RouteMatchInterface $route_match); + public function build(array $build, EntityInterface $left_revision, EntityInterface $right_revision, EntityInterface $entity); } diff --git a/src/Plugin/Layout/ClassicDiffLayout.php b/src/Plugin/Layout/ClassicDiffLayout.php index d07e749..630cf9f 100644 --- a/src/Plugin/Layout/ClassicDiffLayout.php +++ b/src/Plugin/Layout/ClassicDiffLayout.php @@ -5,6 +5,7 @@ namespace Drupal\diff\Plugin\Layout; use Drupal\Component\Render\FormattableMarkup; use Drupal\Component\Utility\Xss; use Drupal\Core\Config\ConfigFactoryInterface; +use Drupal\Core\Datetime\DateFormatter; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; @@ -19,7 +20,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; /** * @DiffLayoutBuilder( - * id = "classic_diff_layout", + * id = "classic_layout", * label = @Translation("Classic"), * ) */ @@ -33,11 +34,6 @@ class ClassicDiffLayout extends DiffLayoutBase { protected $renderer; /** - * Represents non breaking space HTML character entity marked as safe markup. - */ - protected $nonBreakingSpace; - - /** * The diff entity comparison service. */ protected $entityComparison; @@ -67,11 +63,11 @@ class ClassicDiffLayout extends DiffLayoutBase { * @param \Drupal\Core\Render\RendererInterface $renderer * The renderer. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config, EntityTypeManagerInterface $entity_type_manager, DiffEntityParser $entityParser, RendererInterface $renderer, DiffEntityComparison $entityComparison) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config, EntityTypeManagerInterface $entity_type_manager, DiffEntityParser $entityParser, RendererInterface $renderer, DiffEntityComparison $entityComparison, DateFormatter $date) { parent::__construct($configuration, $plugin_id, $plugin_definition, $config, $entity_type_manager, $entityParser); $this->renderer = $renderer; - $this->nonBreakingSpace = new FormattableMarkup(' ', array()); $this->entityComparison = $entityComparison; + $this->date = $date; } /** @@ -86,39 +82,16 @@ class ClassicDiffLayout extends DiffLayoutBase { $container->get('entity.manager'), $container->get('diff.entity_parser'), $container->get('renderer'), - $container->get('diff.entity_comparison') + $container->get('diff.entity_comparison'), + $container->get('date.formatter') ); } /** * {@inheritdoc} */ - public function build(array $build, EntityInterface $left_revision, EntityInterface $right_revision, RouteMatchInterface $route_match) { - $entity_type_id = $left_revision->getEntityTypeId(); - $entity = $route_match->getParameter($entity_type_id); - - $entity_type_id = $entity->getEntityTypeId(); - $storage = $this->entityTypeManager->getStorage($entity_type_id); - - // Get language from the entity context. - $langcode = $entity->language()->getId(); - - // Get left and right revision in current language. - $left_revision = $left_revision->getTranslation($langcode); - $right_revision = $right_revision->getTranslation($langcode); - - $vids = []; - // Filter revisions of current translation and where the translation is - // affected. - foreach ($this->getVids($storage, $entity->id()) as $vid) { - $revision = $storage->loadRevision($vid); - if ($revision->hasTranslation($langcode) && $revision->getTranslation($langcode)->isRevisionTranslationAffected()) { - $vids[] = $vid; - } - } - $diff_rows[] = $this->buildRevisionsNavigation($entity, $vids, $left_revision->getRevisionId(), $right_revision->getRevisionId()); + 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 @@ -156,21 +129,6 @@ class ClassicDiffLayout extends DiffLayoutBase { ), ); - if ($entity->hasLinkTemplate('version-history')) { - $build['back'] = array( - '#type' => 'link', - '#attributes' => array( - 'class' => array( - 'button', - 'diff-button', - ), - ), - '#title' => $this->t('Back to Revision Overview'), - '#url' => Url::fromRoute("entity.$entity_type_id.version_history", [$entity_type_id => $entity->id()]), - ); - } - - $build['#attached']['library'][] = 'diff/diff.general'; $build['#attached']['library'][] = 'diff/diff.github'; return $build; } @@ -225,10 +183,10 @@ class ClassicDiffLayout extends DiffLayoutBase { '#theme' => 'username', '#account' => $revision->uid->entity, ]; - //$revision_date = $this->date->format($revision->getRevisionCreationTime(), 'short'); + $revision_date = $this->date->format($revision->getRevisionCreationTime(), 'short'); $route_name = $entity_type_id != 'node' ? "entity.$entity_type_id.revisions_diff" : 'entity.node.revision'; $revision_link = $this->t($revision_log . '@date', [ - '@date' => \Drupal::l('example', Url::fromRoute($route_name, [ + '@date' => \Drupal::l($revision_date, Url::fromRoute($route_name, [ $entity_type_id => $revision->id(), $entity_type_id . '_revision' => $revision->getRevisionId(), ])), @@ -240,116 +198,4 @@ class ClassicDiffLayout extends DiffLayoutBase { return $revision_link; } - /** - * Returns the navigation row for diff table. - */ - protected function buildRevisionsNavigation(EntityInterface $entity, $vids, $left_vid, $right_vid) { - $revisions_count = count($vids); - $i = 0; - - $row = array(); - // Find the previous revision. - while ($left_vid > $vids[$i]) { - $i += 1; - } - if ($i != 0) { - // Second column. - $row[] = array( - 'data' => \Drupal::l( - $this->t('< Previous difference'), $this->diffRoute($entity, $vids[$i - 1], $left_vid) - ), - 'colspan' => 2, - 'class' => 'rev-navigation', - ); - } - else { - // Second column. - $row[] = $this->nonBreakingSpace; - } - // Third column. - $row[] = $this->nonBreakingSpace; - // Find the next revision. - $i = 0; - while ($i < $revisions_count && $right_vid >= $vids[$i]) { - $i += 1; - } - if ($revisions_count != $i && $vids[$i - 1] != $vids[$revisions_count - 1]) { - // Forth column. - $row[] = array( - 'data' => \Drupal::l( - $this->t('Next difference >'), $this->diffRoute($entity, $right_vid, $vids[$i]) - ), - 'colspan' => 2, - 'class' => 'rev-navigation', - ); - } - else { - // Forth column. - $row[] = $this->nonBreakingSpace; - } - - // If there are only 2 revision return an empty row. - if ($revisions_count == 2) { - return array(); - } - else { - return $row; - } - } - - /** - * Creates an url object for diff. - * - * @param \Drupal\Core\Entity\EntityInterface $entity - * The entity to be compared. - * @param $left_vid - * Vid of the left revision. - * @param $right_vid - * Vid of the right revision. - * @param $filter - * (optional) The filter added to the route. - * - * @return \Drupal\Core\Url - * The URL object. - */ - protected function diffRoute(EntityInterface $entity, $left_vid, $right_vid, $filter = NULL) { - $entity_type_id = $entity->getEntityTypeId(); - // @todo Remove the diff.revisions_diff route so we avoid adding extra cases. - if ($entity->getEntityTypeId() == 'node') { - $route_name = 'diff.revisions_diff'; - } - else { - $route_name = "entity.$entity_type_id.revisions_diff"; - } - $route_parameters = [ - $entity_type_id => $entity->id(), - 'left_revision' => $left_vid, - 'right_revision' => $right_vid, - ]; - if ($filter) { - $route_parameters['filter'] = $filter; - } - return Url::fromRoute($route_name, $route_parameters); - } - - /** - * Get all the revision ids of given entity id. - * - * @param $storage - * The entity storage manager. - * @param $entity_id - * The entity to find revisions of. - * - * @return array - */ - protected function getVids(EntityStorageInterface $storage, $entity_id) { - $result = $storage->getQuery() - ->allRevisions() - ->condition($storage->getEntityType()->getKey('id'), $entity_id) - ->execute(); - $result_array = array_keys($result); - sort($result_array); - return $result_array; - } - } diff --git a/src/Plugin/Layout/ClassicDiffLayout.php b/src/Plugin/Layout/MarkdownDiffLayout.php similarity index 53% copy from src/Plugin/Layout/ClassicDiffLayout.php copy to src/Plugin/Layout/MarkdownDiffLayout.php index d07e749..a78f814 100644 --- a/src/Plugin/Layout/ClassicDiffLayout.php +++ b/src/Plugin/Layout/MarkdownDiffLayout.php @@ -5,6 +5,7 @@ namespace Drupal\diff\Plugin\Layout; use Drupal\Component\Render\FormattableMarkup; use Drupal\Component\Utility\Xss; use Drupal\Core\Config\ConfigFactoryInterface; +use Drupal\Core\Datetime\DateFormatter; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; @@ -19,11 +20,11 @@ use Symfony\Component\DependencyInjection\ContainerInterface; /** * @DiffLayoutBuilder( - * id = "classic_diff_layout", - * label = @Translation("Classic"), + * id = "markdown_layout", + * label = @Translation("Markdown"), * ) */ -class ClassicDiffLayout extends DiffLayoutBase { +class MarkdownDiffLayout extends DiffLayoutBase { /** * The renderer. @@ -33,11 +34,6 @@ class ClassicDiffLayout extends DiffLayoutBase { protected $renderer; /** - * Represents non breaking space HTML character entity marked as safe markup. - */ - protected $nonBreakingSpace; - - /** * The diff entity comparison service. */ protected $entityComparison; @@ -67,11 +63,11 @@ class ClassicDiffLayout extends DiffLayoutBase { * @param \Drupal\Core\Render\RendererInterface $renderer * The renderer. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config, EntityTypeManagerInterface $entity_type_manager, DiffEntityParser $entityParser, RendererInterface $renderer, DiffEntityComparison $entityComparison) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config, EntityTypeManagerInterface $entity_type_manager, DiffEntityParser $entityParser, RendererInterface $renderer, DiffEntityComparison $entityComparison, DateFormatter $date) { parent::__construct($configuration, $plugin_id, $plugin_definition, $config, $entity_type_manager, $entityParser); $this->renderer = $renderer; - $this->nonBreakingSpace = new FormattableMarkup(' ', array()); $this->entityComparison = $entityComparison; + $this->date = $date; } /** @@ -86,39 +82,16 @@ class ClassicDiffLayout extends DiffLayoutBase { $container->get('entity.manager'), $container->get('diff.entity_parser'), $container->get('renderer'), - $container->get('diff.entity_comparison') + $container->get('diff.entity_comparison'), + $container->get('date.formatter') ); } /** * {@inheritdoc} */ - public function build(array $build, EntityInterface $left_revision, EntityInterface $right_revision, RouteMatchInterface $route_match) { - $entity_type_id = $left_revision->getEntityTypeId(); - $entity = $route_match->getParameter($entity_type_id); - - $entity_type_id = $entity->getEntityTypeId(); - $storage = $this->entityTypeManager->getStorage($entity_type_id); - - // Get language from the entity context. - $langcode = $entity->language()->getId(); - - // Get left and right revision in current language. - $left_revision = $left_revision->getTranslation($langcode); - $right_revision = $right_revision->getTranslation($langcode); - - $vids = []; - // Filter revisions of current translation and where the translation is - // affected. - foreach ($this->getVids($storage, $entity->id()) as $vid) { - $revision = $storage->loadRevision($vid); - if ($revision->hasTranslation($langcode) && $revision->getTranslation($langcode)->isRevisionTranslationAffected()) { - $vids[] = $vid; - } - } - $diff_rows[] = $this->buildRevisionsNavigation($entity, $vids, $left_revision->getRevisionId(), $right_revision->getRevisionId()); + 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 @@ -133,8 +106,8 @@ class ClassicDiffLayout extends DiffLayoutBase { ); } $field_diff_rows = $this->entityComparison->getRows( - $field['#states']['raw']['#left'], - $field['#states']['raw']['#right'] + $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. @@ -156,21 +129,6 @@ class ClassicDiffLayout extends DiffLayoutBase { ), ); - if ($entity->hasLinkTemplate('version-history')) { - $build['back'] = array( - '#type' => 'link', - '#attributes' => array( - 'class' => array( - 'button', - 'diff-button', - ), - ), - '#title' => $this->t('Back to Revision Overview'), - '#url' => Url::fromRoute("entity.$entity_type_id.version_history", [$entity_type_id => $entity->id()]), - ); - } - - $build['#attached']['library'][] = 'diff/diff.general'; $build['#attached']['library'][] = 'diff/diff.github'; return $build; } @@ -225,10 +183,10 @@ class ClassicDiffLayout extends DiffLayoutBase { '#theme' => 'username', '#account' => $revision->uid->entity, ]; - //$revision_date = $this->date->format($revision->getRevisionCreationTime(), 'short'); + $revision_date = $this->date->format($revision->getRevisionCreationTime(), 'short'); $route_name = $entity_type_id != 'node' ? "entity.$entity_type_id.revisions_diff" : 'entity.node.revision'; $revision_link = $this->t($revision_log . '@date', [ - '@date' => \Drupal::l('example', Url::fromRoute($route_name, [ + '@date' => \Drupal::l($revision_date, Url::fromRoute($route_name, [ $entity_type_id => $revision->id(), $entity_type_id . '_revision' => $revision->getRevisionId(), ])), @@ -240,116 +198,4 @@ class ClassicDiffLayout extends DiffLayoutBase { return $revision_link; } - /** - * Returns the navigation row for diff table. - */ - protected function buildRevisionsNavigation(EntityInterface $entity, $vids, $left_vid, $right_vid) { - $revisions_count = count($vids); - $i = 0; - - $row = array(); - // Find the previous revision. - while ($left_vid > $vids[$i]) { - $i += 1; - } - if ($i != 0) { - // Second column. - $row[] = array( - 'data' => \Drupal::l( - $this->t('< Previous difference'), $this->diffRoute($entity, $vids[$i - 1], $left_vid) - ), - 'colspan' => 2, - 'class' => 'rev-navigation', - ); - } - else { - // Second column. - $row[] = $this->nonBreakingSpace; - } - // Third column. - $row[] = $this->nonBreakingSpace; - // Find the next revision. - $i = 0; - while ($i < $revisions_count && $right_vid >= $vids[$i]) { - $i += 1; - } - if ($revisions_count != $i && $vids[$i - 1] != $vids[$revisions_count - 1]) { - // Forth column. - $row[] = array( - 'data' => \Drupal::l( - $this->t('Next difference >'), $this->diffRoute($entity, $right_vid, $vids[$i]) - ), - 'colspan' => 2, - 'class' => 'rev-navigation', - ); - } - else { - // Forth column. - $row[] = $this->nonBreakingSpace; - } - - // If there are only 2 revision return an empty row. - if ($revisions_count == 2) { - return array(); - } - else { - return $row; - } - } - - /** - * Creates an url object for diff. - * - * @param \Drupal\Core\Entity\EntityInterface $entity - * The entity to be compared. - * @param $left_vid - * Vid of the left revision. - * @param $right_vid - * Vid of the right revision. - * @param $filter - * (optional) The filter added to the route. - * - * @return \Drupal\Core\Url - * The URL object. - */ - protected function diffRoute(EntityInterface $entity, $left_vid, $right_vid, $filter = NULL) { - $entity_type_id = $entity->getEntityTypeId(); - // @todo Remove the diff.revisions_diff route so we avoid adding extra cases. - if ($entity->getEntityTypeId() == 'node') { - $route_name = 'diff.revisions_diff'; - } - else { - $route_name = "entity.$entity_type_id.revisions_diff"; - } - $route_parameters = [ - $entity_type_id => $entity->id(), - 'left_revision' => $left_vid, - 'right_revision' => $right_vid, - ]; - if ($filter) { - $route_parameters['filter'] = $filter; - } - return Url::fromRoute($route_name, $route_parameters); - } - - /** - * Get all the revision ids of given entity id. - * - * @param $storage - * The entity storage manager. - * @param $entity_id - * The entity to find revisions of. - * - * @return array - */ - protected function getVids(EntityStorageInterface $storage, $entity_id) { - $result = $storage->getQuery() - ->allRevisions() - ->condition($storage->getEntityType()->getKey('id'), $entity_id) - ->execute(); - $result_array = array_keys($result); - sort($result_array); - return $result_array; - } - } diff --git a/src/Routing/DiffRouteProvider.php b/src/Routing/DiffRouteProvider.php index dc1f411..0c0cd2e 100644 --- a/src/Routing/DiffRouteProvider.php +++ b/src/Routing/DiffRouteProvider.php @@ -37,7 +37,7 @@ class DiffRouteProvider implements EntityRouteProviderInterface { $route = new Route($entity_type->getLinkTemplate('revisions-diff')); $route->addDefaults([ '_controller' => '\Drupal\diff\Controller\PluginRevisionController::compareEntityRevisions', - 'filter' => 'raw', + 'filter' => 'classic_layout', ]); $route->addRequirements([ '_entity_access' => $entity_type->id() . '.view',