From 6e046c385b1dc851eff2e8c5663c095a289018b5 Mon Sep 17 00:00:00 2001 From: Eli Zoller Date: Fri, 9 Aug 2019 16:00:15 -0700 Subject: [PATCH] check if the entityType isVersionable and check if it shouldCreateNewRevision before setting the Version flag --- src/EventGenerator/EventGenerator.php | 33 ++++++++++++++++++++------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/src/EventGenerator/EventGenerator.php b/src/EventGenerator/EventGenerator.php index 4debec35..865c9b90 100644 --- a/src/EventGenerator/EventGenerator.php +++ b/src/EventGenerator/EventGenerator.php @@ -12,7 +12,8 @@ use Drupal\user\UserInterface; * * Provides Activity Stream 2.0 serialized events. */ -class EventGenerator implements EventGeneratorInterface { +class EventGenerator implements EventGeneratorInterface +{ /** * Islandora utils. @@ -36,7 +37,8 @@ class EventGenerator implements EventGeneratorInterface { * @param \Drupal\islandora\MediaSource\MediaSourceService $media_source * Media source service. */ - public function __construct(IslandoraUtils $utils, MediaSourceService $media_source) { + public function __construct(IslandoraUtils $utils, MediaSourceService $media_source) + { $this->utils = $utils; $this->mediaSource = $media_source; } @@ -44,7 +46,8 @@ class EventGenerator implements EventGeneratorInterface { /** * {@inheritdoc} */ - public function generateEvent(EntityInterface $entity, UserInterface $user, array $data) { + public function generateEvent(EntityInterface $entity, UserInterface $user, array $data) + { $user_url = $this->utils->getEntityUrl($user); @@ -53,8 +56,7 @@ class EventGenerator implements EventGeneratorInterface { if ($entity_type == 'file') { $entity_url = $this->utils->getDownloadUrl($entity); $mimetype = $entity->getMimeType(); - } - else { + } else { $entity_url = $this->utils->getEntityUrl($entity); $mimetype = 'text/html'; } @@ -93,13 +95,17 @@ class EventGenerator implements EventGeneratorInterface { if ($data["event"] == "Generate Derivative") { $event["type"] = "Activity"; $event["summary"] = $data["event"]; - } - else { + } else { $event["type"] = ucfirst($data["event"]); $event["summary"] = ucfirst($data["event"]) . " a " . ucfirst($entity_type); } - $event["object"]["type"] = $event["type"]; + if ($entity->getEntityType()->isRevisionable()) { + $isNewRev = $this->isNewRevision($entity); + if ($isNewRev) { + $event["object"]["type"] = "Version"; + } + } // Add REST links for non-file entities. if ($entity_type != 'file') { @@ -147,4 +153,15 @@ class EventGenerator implements EventGeneratorInterface { return json_encode($event); } + /** + * @param $entity EntityInterface + * returns Boolean + */ + protected function isNewRevision(EntityInterface $entity) + { + // revisions tab. + $bundle_entity_type = $entity->getEntityType()->getBundleEntityType(); + $bundle_entity = \Drupal::entityTypeManager()->getStorage($bundle_entity_type)->load($entity->bundle()); + return $bundle_entity->shouldCreateNewRevision(); + } }