public function CreateNewRevision::onPreEntitySave in Acquia Content Hub 8.2
Creates a new revision for revisionable entities being imported.
Parameters
\Drupal\acquia_contenthub\Event\PreEntitySaveEvent $event: The pre entity save event.
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
\Drupal\Component\Plugin\Exception\PluginNotFoundException
File
- src/
EventSubscriber/ PreEntitySave/ CreateNewRevision.php, line 54
Class
- CreateNewRevision
- Prepares the entity for a new revision if it is configured to do so.
Namespace
Drupal\acquia_contenthub\EventSubscriber\PreEntitySaveCode
public function onPreEntitySave(PreEntitySaveEvent $event) {
$entity = $event
->getEntity();
// Check whether the entity is configured to create a new revision
// every time it is saved or if we're saving an entity that
// has been stubbed.
$bundle_entity_type = $entity
->getEntityType()
->getBundleEntityType();
if (!$bundle_entity_type || $this->stubTracker
->hasStub($entity
->getEntityTypeId(), $entity
->id())) {
return;
}
$bundle = $this
->getEntityTypeManager()
->getStorage($bundle_entity_type)
->load($entity
->bundle());
$should_create_new_revision = $bundle instanceof RevisionableEntityBundleInterface && $bundle
->shouldCreateNewRevision();
if ($entity
->getEntityType()
->isRevisionable() && $should_create_new_revision) {
$entity
->setNewRevision(TRUE);
}
}