Browse Source

different method of checking for media revisions

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

32
src/EventGenerator/EventGenerator.php

@ -6,6 +6,8 @@ use Drupal\Core\Entity\EntityInterface;
use Drupal\islandora\IslandoraUtils; use Drupal\islandora\IslandoraUtils;
use Drupal\islandora\MediaSource\MediaSourceService; use Drupal\islandora\MediaSource\MediaSourceService;
use Drupal\user\UserInterface; use Drupal\user\UserInterface;
use Drupal\media\Entity\Media;
use Drupal\Core\Entity\EntityStorageInterface;
/** /**
* The default EventGenerator implementation. * The default EventGenerator implementation.
@ -102,6 +104,7 @@ class EventGenerator implements EventGeneratorInterface {
if ($entity->getEntityType()->isRevisionable()) { if ($entity->getEntityType()->isRevisionable()) {
\Drupal::logger('islandora')->notice('its revisionable'); \Drupal::logger('islandora')->notice('its revisionable');
$isNewRev = $this->isNewRevision($entity); $isNewRev = $this->isNewRevision($entity);
\Drupal::logger('is new revision')->notice($isNewRev);
} }
$event["object"]["isNewVersion"] = $isNewRev; $event["object"]["isNewVersion"] = $isNewRev;
@ -161,8 +164,33 @@ class EventGenerator implements EventGeneratorInterface {
* Is new version. * Is new version.
*/ */
protected function isNewRevision(EntityInterface $entity) { protected function isNewRevision(EntityInterface $entity) {
$revision_ids = \Drupal::entityTypeManager()->getStorage($entity->getEntityTypeId())->revisionIds($entity); if ($entity->getEntityTypeId() == "node") {
return count($revision_ids) > 1; $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);
} }
} }

Loading…
Cancel
Save