ConfigEntityRevisionsDiffController.php in Config Entity Revisions 1.x
File
src/ConfigEntityRevisionsDiffController.php
View source
<?php
namespace Drupal\config_entity_revisions;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\diff\Controller\PluginRevisionController;
use Drupal\diff\DiffEntityComparison;
use Drupal\diff\DiffLayoutManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
class ConfigEntityRevisionsDiffController extends PluginRevisionController {
public function __construct(DiffEntityComparison $entity_comparison, DiffLayoutManager $diff_layout_manager, RequestStack $request_stack, EntityTypeManagerInterface $entityTypeManager) {
parent::__construct($entity_comparison, $diff_layout_manager, $request_stack);
$this->entityTypeManager = $entityTypeManager;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('diff.entity_comparison'), $container
->get('plugin.manager.diff.layout'), $container
->get('request_stack'), $container
->get('entity_type.manager'));
}
public function compareConfigEntityRevisions($config_entity_type, $config_entity_id, $left_revision, $right_revision, $filter) {
$entity_type = $this->entityTypeManager
->getDefinition($config_entity_type);
$class = $entity_type
->get('class');
if (!in_array('Drupal\\config_entity_revisions\\ConfigEntityRevisionsInterface', class_implements($class))) {
return [];
}
$storage = $this->entityTypeManager
->getStorage($config_entity_type);
$route_match = \Drupal::routeMatch();
$left_revision = $storage
->loadRevision($left_revision);
$right_revision = $storage
->loadRevision($right_revision);
$build = $this
->compareEntityRevisions($route_match, $left_revision, $right_revision, $filter);
return $build;
}
}