Browse Source

check if the entityType isVersionable and check if it shouldCreateNewRevision before setting the Version flag

pull/733/head
Eli Zoller 6 years ago
parent
commit
6e046c385b
  1. 33
      src/EventGenerator/EventGenerator.php

33
src/EventGenerator/EventGenerator.php

@ -12,7 +12,8 @@ use Drupal\user\UserInterface;
* *
* Provides Activity Stream 2.0 serialized events. * Provides Activity Stream 2.0 serialized events.
*/ */
class EventGenerator implements EventGeneratorInterface { class EventGenerator implements EventGeneratorInterface
{
/** /**
* Islandora utils. * Islandora utils.
@ -36,7 +37,8 @@ class EventGenerator implements EventGeneratorInterface {
* @param \Drupal\islandora\MediaSource\MediaSourceService $media_source * @param \Drupal\islandora\MediaSource\MediaSourceService $media_source
* Media source service. * Media source service.
*/ */
public function __construct(IslandoraUtils $utils, MediaSourceService $media_source) { public function __construct(IslandoraUtils $utils, MediaSourceService $media_source)
{
$this->utils = $utils; $this->utils = $utils;
$this->mediaSource = $media_source; $this->mediaSource = $media_source;
} }
@ -44,7 +46,8 @@ class EventGenerator implements EventGeneratorInterface {
/** /**
* {@inheritdoc} * {@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); $user_url = $this->utils->getEntityUrl($user);
@ -53,8 +56,7 @@ class EventGenerator implements EventGeneratorInterface {
if ($entity_type == 'file') { if ($entity_type == 'file') {
$entity_url = $this->utils->getDownloadUrl($entity); $entity_url = $this->utils->getDownloadUrl($entity);
$mimetype = $entity->getMimeType(); $mimetype = $entity->getMimeType();
} } else {
else {
$entity_url = $this->utils->getEntityUrl($entity); $entity_url = $this->utils->getEntityUrl($entity);
$mimetype = 'text/html'; $mimetype = 'text/html';
} }
@ -93,13 +95,17 @@ class EventGenerator implements EventGeneratorInterface {
if ($data["event"] == "Generate Derivative") { if ($data["event"] == "Generate Derivative") {
$event["type"] = "Activity"; $event["type"] = "Activity";
$event["summary"] = $data["event"]; $event["summary"] = $data["event"];
} } else {
else {
$event["type"] = ucfirst($data["event"]); $event["type"] = ucfirst($data["event"]);
$event["summary"] = ucfirst($data["event"]) . " a " . ucfirst($entity_type); $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. // Add REST links for non-file entities.
if ($entity_type != 'file') { if ($entity_type != 'file') {
@ -147,4 +153,15 @@ class EventGenerator implements EventGeneratorInterface {
return json_encode($event); 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();
}
} }

Loading…
Cancel
Save