diff --git a/src/Controller/PluginRevisionController.php b/src/Controller/PluginRevisionController.php index 8515d09..2c9a673 100644 --- a/src/Controller/PluginRevisionController.php +++ b/src/Controller/PluginRevisionController.php @@ -2,6 +2,7 @@ namespace Drupal\diff\Controller; +use Drupal\Core\Datetime\DateFormatter; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Routing\RouteMatchInterface; @@ -41,7 +42,7 @@ class PluginRevisionController extends ControllerBase { * @param DiffLayoutManager $diff_layout_manager * DiffLayoutManager service. */ - public function __construct(DiffEntityComparison $entity_comparison, DiffLayoutManager $diff_layout_manager) { + public function __construct(DateFormatter $date, DiffEntityComparison $entity_comparison, DiffLayoutManager $diff_layout_manager) { $this->config = $this->config('diff.settings'); $this->diffLayoutManager = $diff_layout_manager; $this->entityComparison = $entity_comparison; @@ -104,7 +105,7 @@ class PluginRevisionController extends ControllerBase { $links = []; foreach ($this->diffLayoutManager->getDefinitions() as $key => $value) { $links[$key] = array( - 'title' => $this->t($value['label']), + 'title' => $value['label'], 'url' => $this->diffRoute($entity, $left_revision->getRevisionId(), $right_revision->getRevisionId(), $key), ); } @@ -117,8 +118,8 @@ class PluginRevisionController extends ControllerBase { // 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($filter); - $plugin->build($build, $left_revision, $right_revision); + $plugin = $this->diffLayoutManager->createInstance('classic_diff_layout'); + $build = $plugin->build($build, $left_revision, $right_revision, $route_match); } return $build; } diff --git a/src/DiffLayoutBase.php b/src/DiffLayoutBase.php index bc573ab..29684e7 100644 --- a/src/DiffLayoutBase.php +++ b/src/DiffLayoutBase.php @@ -99,7 +99,7 @@ abstract class DiffLayoutBase extends PluginBase implements DiffLayoutInterface, * {@inheritdoc} */ public function getConfiguration() { - return $this->configFactory->getEditable('diff.plugins'); + return $this->configFactory->getEditable('diff.layout_plugins'); } /** diff --git a/src/Plugin/Layout/ClassicDiffLayout.php b/src/Plugin/Layout/ClassicDiffLayout.php index 9094000..4acca6d 100644 --- a/src/Plugin/Layout/ClassicDiffLayout.php +++ b/src/Plugin/Layout/ClassicDiffLayout.php @@ -18,7 +18,7 @@ use Drupal\node\NodeInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** - * @DiffLayout( + * @DiffLayoutBuilder( * id = "classic_diff_layout", * label = @Translation("Classic diff layout"), * ) @@ -43,6 +43,13 @@ class ClassicDiffLayout extends DiffLayoutBase { protected $entityComparison; /** + * The date service. + * + * @var \Drupal\Core\Datetime\DateFormatter + */ + protected $date; + + /** * Constructs a FieldDiffBuilderBase object. * * @param array $configuration @@ -91,7 +98,7 @@ class ClassicDiffLayout extends DiffLayoutBase { $entity = $route_match->getParameter($entity_type_id); $entity_type_id = $entity->getEntityTypeId(); - $storage = $this->entityTypeManager()->getStorage($entity_type_id); + $storage = \Drupal::entityTypeManager()->getStorage($entity_type_id); // Get language from the entity context. $langcode = $entity->language()->getId(); @@ -110,7 +117,7 @@ class ClassicDiffLayout extends DiffLayoutBase { } } $diff_rows[] = $this->buildRevisionsNavigation($entity, $vids, $left_revision->getRevisionId(), $right_revision->getRevisionId()); - $diff_rows[] = $this->buildMarkdownNavigation($entity, $left_revision->getRevisionId(), $right_revision->getRevisionId(), $filter); + $diff_rows[] = $this->buildMarkdownNavigation($entity, $left_revision->getRevisionId(), $right_revision->getRevisionId(), 'raw'); $diff_header = $this->buildTableHeader($left_revision, $right_revision); // Perform comparison only if both entity revisions loaded successfully. @@ -127,8 +134,8 @@ class ClassicDiffLayout extends DiffLayoutBase { ); } $field_diff_rows = $this->entityComparison->getRows( - $field['#states'][$filter]['#left'], - $field['#states'][$filter]['#right'] + $field['#states']['raw']['#left'], + $field['#states']['raw']['#right'] ); // Add the field label to the table only if there are changes to that field. @@ -227,17 +234,17 @@ 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' => $this->l($revision_date, Url::fromRoute($route_name, [ + '@date' => \Drupal::l('example', Url::fromRoute($route_name, [ $entity_type_id => $revision->id(), $entity_type_id . '_revision' => $revision->getRevisionId(), ])), ]); } else { - $revision_link = $this->l($revision->label(), $revision->toUrl('revision')); + $revision_link = \Drupal::l($revision->label(), $revision->toUrl('revision')); } return $revision_link; } @@ -257,7 +264,7 @@ class ClassicDiffLayout extends DiffLayoutBase { if ($i != 0) { // Second column. $row[] = array( - 'data' => $this->l( + 'data' => \Drupal::l( $this->t('< Previous difference'), $this->diffRoute($entity, $vids[$i - 1], $left_vid) ), 'colspan' => 2, @@ -278,7 +285,7 @@ class ClassicDiffLayout extends DiffLayoutBase { if ($revisions_count != $i && $vids[$i - 1] != $vids[$revisions_count - 1]) { // Forth column. $row[] = array( - 'data' => $this->l( + 'data' => \Drupal::l( $this->t('Next difference >'), $this->diffRoute($entity, $right_vid, $vids[$i]) ), 'colspan' => 2, diff --git a/src/Routing/DiffRouteProvider.php b/src/Routing/DiffRouteProvider.php index b825b54..dc1f411 100644 --- a/src/Routing/DiffRouteProvider.php +++ b/src/Routing/DiffRouteProvider.php @@ -36,7 +36,7 @@ class DiffRouteProvider implements EntityRouteProviderInterface { if ($entity_type->hasLinkTemplate('revisions-diff')) { $route = new Route($entity_type->getLinkTemplate('revisions-diff')); $route->addDefaults([ - '_controller' => '\Drupal\diff\Controller\GenericRevisionController::compareEntityRevisions', + '_controller' => '\Drupal\diff\Controller\PluginRevisionController::compareEntityRevisions', 'filter' => 'raw', ]); $route->addRequirements([