|
|
|
|
@ -6,6 +6,8 @@ use Drupal\Core\Entity\EntityInterface;
|
|
|
|
|
use Drupal\islandora\IslandoraUtils; |
|
|
|
|
use Drupal\islandora\MediaSource\MediaSourceService; |
|
|
|
|
use Drupal\user\UserInterface; |
|
|
|
|
use Drupal\media\Entity\Media; |
|
|
|
|
use Drupal\Core\Entity\EntityStorageInterface; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* The default EventGenerator implementation. |
|
|
|
|
@ -102,6 +104,7 @@ class EventGenerator implements EventGeneratorInterface {
|
|
|
|
|
if ($entity->getEntityType()->isRevisionable()) { |
|
|
|
|
\Drupal::logger('islandora')->notice('its revisionable'); |
|
|
|
|
$isNewRev = $this->isNewRevision($entity); |
|
|
|
|
\Drupal::logger('is new revision')->notice($isNewRev); |
|
|
|
|
} |
|
|
|
|
$event["object"]["isNewVersion"] = $isNewRev; |
|
|
|
|
|
|
|
|
|
@ -161,8 +164,33 @@ class EventGenerator implements EventGeneratorInterface {
|
|
|
|
|
* Is new version. |
|
|
|
|
*/ |
|
|
|
|
protected function isNewRevision(EntityInterface $entity) { |
|
|
|
|
$revision_ids = \Drupal::entityTypeManager()->getStorage($entity->getEntityTypeId())->revisionIds($entity); |
|
|
|
|
return count($revision_ids) > 1; |
|
|
|
|
if ($entity->getEntityTypeId() == "node") { |
|
|
|
|
$revision_ids = \Drupal::entityTypeManager()->getStorage($entity->getEntityTypeId())->revisionIds($entity); |
|
|
|
|
return count($revision_ids) > 1; |
|
|
|
|
} |
|
|
|
|
elseif ($entity->getEntityTypeId() == "media") { |
|
|
|
|
$mediaStorage = \Drupal::entityTypeManager()->getStorage($entity->getEntityTypeId()); |
|
|
|
|
return count($this->getRevisionIds($entity, $mediaStorage)) > 1; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Method to get the revisionIds of a media object. |
|
|
|
|
* |
|
|
|
|
* @param \Drupal\media\Entity\Media $media |
|
|
|
|
* Media object. |
|
|
|
|
* @param \Drupal\Core\Entity\EntityStorageInterface $media_storage |
|
|
|
|
* Media Storage. |
|
|
|
|
*/ |
|
|
|
|
protected function getRevisionIds(Media $media, EntityStorageInterface $media_storage) { |
|
|
|
|
$result = $media_storage->getQuery() |
|
|
|
|
->allRevisions() |
|
|
|
|
->condition($media->getEntityType()->getKey('id'), $media->id()) |
|
|
|
|
->sort($media->getEntityType()->getKey('revision'), 'DESC') |
|
|
|
|
->pager(50) |
|
|
|
|
->execute(); |
|
|
|
|
// \Drupal::logger('revision array')->notice('<pre><code>' . print_r(array_keys($result), TRUE) . '</code></pre>'); |
|
|
|
|
return array_keys($result); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|