Skip to content

Commit 7dedc5f

Browse files
Steve WirtSteve Wirt
authored andcommitted
#4621 Add revision time on presave.
1 parent ef3d2c0 commit 7dedc5f

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

modules/metastore/metastore.module

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
*/
66

77
use Drupal\Core\Database\Query\AlterableInterface;
8-
use Drupal\Core\Entity\EntityTypeInterface;
98
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
109
use Drupal\Core\Entity\EntityInterface;
10+
use Drupal\Core\Entity\EntityTypeInterface;
1111
use Drupal\Core\Form\FormStateInterface;
12-
use Drupal\metastore\NodeWrapper\Data;
1312
use Drupal\metastore\MetastoreService;
13+
use Drupal\metastore\NodeWrapper\Data;
14+
use Drupal\metastore\Factory\MetastoreEntityItemFactoryInterface;
1415
use Drupal\metastore\Service\OrphanNodeProcessor;
1516

1617
/**
@@ -27,6 +28,15 @@ function metastore_entity_load(array $entities) {
2728
* Implements hook_entity_presave().
2829
*/
2930
function metastore_entity_presave(EntityInterface $entity) {
31+
// Check if the entity is a data entity and a new revision is being created.
32+
/** @var MetastoreEntityItemFactoryInterface $storage */
33+
$metastore_service = \Drupal::service('dkan.metastore.metastore_item_factory');
34+
if ($entity->getEntityTypeId() === $metastore_service::getEntityType() && in_array($entity->bundle(), $metastore_service::getBundles()) && $entity->isNewRevision()) {
35+
// Set revision creation time to the current time because programmatically
36+
// saved revisions will reuse the previous revision's timestamp if not
37+
// explicitly set.
38+
$entity->setRevisionCreationTime(\Drupal::time()->getCurrentTime());
39+
}
3040
metastore_data_lifecycle([$entity], "presave");
3141
}
3242

0 commit comments

Comments
 (0)