You are here

public function MultiversionManager::newRevisionId in Multiversion 8

Same name and namespace in other branches
  1. 8.2 src/MultiversionManager.php \Drupal\multiversion\MultiversionManager::newRevisionId()

Return value

string

Overrides MultiversionManagerInterface::newRevisionId

File

src/MultiversionManager.php, line 463

Class

MultiversionManager

Namespace

Drupal\multiversion

Code

public function newRevisionId(ContentEntityInterface $entity, $index = 0) {
  $deleted = $entity->_deleted->value;
  $old_rev = $entity->_rev->value;

  // The 'new_revision_id' context will be used in normalizers (where it's
  // necessary) to identify in which format to return the normalized entity.
  $normalized_entity = $this->serializer
    ->normalize($entity, NULL, [
    'new_revision_id' => TRUE,
  ]);

  // Remove fields internal to the multiversion system.
  $this
    ->filterNormalizedEntity($normalized_entity);

  // The terms being serialized are:
  // - deleted
  // - old sequence ID (@todo: {@link https://www.drupal.org/node/2597341
  // Address this property.})
  // - old revision hash
  // - normalized entity (without revision info field)
  // - attachments (@todo: {@link https://www.drupal.org/node/2597341
  // Address this property.})
  return $index + 1 . '-' . md5($this
    ->termToBinary([
    $deleted,
    0,
    $old_rev,
    $normalized_entity,
    [],
  ]));
}