You are here

public function GroupStorage::restore in Group 8

Same name and namespace in other branches
  1. 2.0.x src/Entity/Storage/GroupStorage.php \Drupal\group\Entity\Storage\GroupStorage::restore()

Restores a previously saved entity.

Note that the entity is assumed to be in a valid state for the storage, so the restore process does not invoke any hooks, nor does it perform any pre or post-save operations.

@internal This method should never be used to perform a regular entity save. Its only use-case is to assist updating entity types when there are complex schema changes, for example, to make them revisionable. Note that overriding this method to fix data prior to restoring is a likely sign that the current data is corrupt.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity to restore.

Throws

\Drupal\Core\Entity\EntityStorageException In case of failures, an exception is thrown.

Overrides SqlContentEntityStorage::restore

File

src/Entity/Storage/GroupStorage.php, line 16

Class

GroupStorage
Defines the storage handler class for group entities.

Namespace

Drupal\group\Entity\Storage

Code

public function restore(EntityInterface $entity) {

  // It seems that SqlFieldableEntityTypeListenerTrait::copyData() does not
  // care about the revision creation time or user at all, leading to broken
  // UIs after the update that enabled revisions. To fix this, we implement
  // the necessary logic here, but ideally this should be fixed in core.

  /** @var \Drupal\group\Entity\GroupInterface $entity */
  if (!$entity
    ->getRevisionCreationTime()) {
    $entity
      ->setRevisionCreationTime($entity
      ->getCreatedTime());
  }
  if (!$entity
    ->getRevisionUser()) {
    $entity
      ->setRevisionUserId($entity
      ->getOwnerId());
  }
  if (!$entity
    ->getRevisionLogMessage()) {
    $entity
      ->setRevisionLogMessage('');
  }
  parent::restore($entity);
}