X-Git-Url: https://yaffs.net/gitweb/?a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fdiff%2Fsrc%2FController%2FPluginRevisionController.php;fp=web%2Fmodules%2Fcontrib%2Fdiff%2Fsrc%2FController%2FPluginRevisionController.php;h=7b6a53d9c8d124e68b98605f299cf95afdc151f2;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website
diff --git a/web/modules/contrib/diff/src/Controller/PluginRevisionController.php b/web/modules/contrib/diff/src/Controller/PluginRevisionController.php
new file mode 100644
index 000000000..7b6a53d9c
--- /dev/null
+++ b/web/modules/contrib/diff/src/Controller/PluginRevisionController.php
@@ -0,0 +1,327 @@
+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' => '