public static function AdminHelper::prepareNewRevision in Search and Replace Scanner 8
Prepares a new revision of a given entity, if applicable.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: An entity.
string|\Drupal\Core\StringTranslation\TranslatableMarkup $message: A revision log message to set.
int $current_uid: The user ID of the current logged-in user.
Return value
\Drupal\Core\Entity\EntityInterface The moderation state for the given entity.
File
- src/
AdminHelper.php, line 122
Class
- AdminHelper
- Shared logic for use in the mdoule.
Namespace
Drupal\scannerCode
public static function prepareNewRevision(EntityInterface $entity, $message, $current_uid) {
$storage = \Drupal::entityTypeManager()
->getStorage($entity
->getEntityTypeId());
if ($storage instanceof ContentEntityStorageInterface) {
$revision = $storage
->createRevision($entity);
if ($revision instanceof RevisionLogInterface) {
$revision
->setRevisionLogMessage($message);
$revision
->setRevisionCreationTime(\Drupal::time()
->getRequestTime());
$revision
->setRevisionUserId($current_uid);
}
return $revision;
}
return $entity;
}