config = $this->config('diff.settings');
$this->diffLayoutManager = $diff_layout_manager;
$this->entityComparison = $entity_comparison;
$this->requestStack = $request_stack;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('diff.entity_comparison'),
$container->get('plugin.manager.diff.layout'),
$container->get('request_stack')
);
}
/**
* Get all the revision ids of given entity id.
*
* @param \Drupal\Core\Entity\EntityStorageInterface $storage
* The entity storage manager.
* @param int $entity_id
* The entity to find revisions of.
*
* @return int[]
* The revision ids.
*/
public function getRevisionIds(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;
}
/**
* Returns a table which shows the differences between two entity revisions.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match.
* @param \Drupal\Core\Entity\ContentEntityInterface $left_revision
* The left revision.
* @param \Drupal\Core\Entity\ContentEntityInterface $right_revision
* The right revision.
* @param string $filter
* If $filter == 'raw' raw text is compared (including html tags)
* If filter == 'raw-plain' markdown function is applied to the text before comparison.
*
* @return array
* Table showing the diff between the two entity revisions.
*/
public function compareEntityRevisions(RouteMatchInterface $route_match, ContentEntityInterface $left_revision, ContentEntityInterface $right_revision, $filter) {
$entity_type_id = $left_revision->getEntityTypeId();
/** @var \Drupal\Core\Entity\EntityInterface $entity */
$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);
$revisions_ids = [];
// Filter revisions of current translation and where the translation is
// affected.
foreach ($this->getRevisionIds($storage, $entity->id()) as $revision_id) {
/** @var \Drupal\Core\Entity\ContentEntityInterface $revision */
$revision = $storage->loadRevision($revision_id);
if ($revision->hasTranslation($langcode) && $revision->getTranslation($langcode)->isRevisionTranslationAffected()) {
$revisions_ids[] = $revision_id;
}
}
$build = [
'#title' => $this->t('Changes to %title', ['%title' => $entity->label()]),
'header' => [
'#prefix' => '