Skip to content

Commit

Permalink
Term revisions can now go to Fedora (#1043)
Browse files Browse the repository at this point in the history
* Allow revisioning taxonomy terms.
  • Loading branch information
rosiel authored Jul 17, 2024
1 parent 7bae08f commit 4821cca
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/EventGenerator/EventGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace Drupal\islandora\EventGenerator;

use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Site\Settings;
use Drupal\islandora\IslandoraUtils;
use Drupal\islandora\MediaSource\MediaSourceService;
use Drupal\user\UserInterface;
use Drupal\Core\Site\Settings;
use Drupal\media\Entity\Media;
use Drupal\Core\Entity\EntityStorageInterface;

/**
* The default EventGenerator implementation.
Expand Down Expand Up @@ -186,26 +186,26 @@ protected function isNewRevision(EntityInterface $entity) {
$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;
elseif (in_array($entity->getEntityTypeId(), ["media", "taxonomy_term"])) {
$entity_storage = \Drupal::entityTypeManager()->getStorage($entity->getEntityTypeId());
return count($this->getRevisionIds($entity, $entity_storage)) > 1;
}
}

/**
* Method to get the revisionIds of a media object.
* Method to get the revisionIds of an entity.
*
* @param \Drupal\media\Entity\Media $media
* Media object.
* @param \Drupal\Core\Entity\EntityStorageInterface $media_storage
* Media Storage.
* @param \Drupal\entity\Entity\ContentEntityInterface $entity
* Entity instance such as a Media or Taxonomy term.
* @param \Drupal\Core\Entity\EntityStorageInterface $entity_storage
* Entity Storage.
*/
protected function getRevisionIds(Media $media, EntityStorageInterface $media_storage) {
$result = $media_storage->getQuery()
protected function getRevisionIds(ContentEntityInterface $entity, EntityStorageInterface $entity_storage) {
$result = $entity_storage->getQuery()
->allRevisions()
->accessCheck(TRUE)
->condition($media->getEntityType()->getKey('id'), $media->id())
->sort($media->getEntityType()->getKey('revision'), 'DESC')
->condition($entity->getEntityType()->getKey('id'), $entity->id())
->sort($entity->getEntityType()->getKey('revision'), 'DESC')
->execute();
return array_keys($result);
}
Expand Down

0 comments on commit 4821cca

Please sign in to comment.