Skip to content

Commit

Permalink
add loadRevision functionality (#5717)
Browse files Browse the repository at this point in the history
* add loadRevision functionality

* comments
  • Loading branch information
chx committed Jul 24, 2023
1 parent 47377de commit 31c64d7
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Commands/core/CliCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public function docs(): void
#[CLI\Option(name: 'cwd', description: 'A directory to change to before launching the shell. Default is the project root directory')]
#[CLI\Topics(topics: [self::DOCS_REPL])]
#[CLI\Usage(name: '$node = Node::load(1)', description: 'Entity classes are available without their namespace. For example, Node::load(1) works instead of Drupal\Node\entity\Node::load(1).')]
#[CLI\Usage(name: '$paragraph = Paragraph::loadRevision(1)', description: 'Also, a loadRevision static method is made available for easier load of revisions.')]
#[CLI\Bootstrap(level: DrupalBootLevels::FULL)]
public function cli(array $options = ['version-history' => false, 'cwd' => self::REQ]): void
{
Expand Down Expand Up @@ -308,7 +309,15 @@ public function makeEntitiesAvailableWithShortClassNames(): void
foreach ($this->entityTypeManager->getDefinitions() as $definition) {
$class = $definition->getClass();
$parts = explode('\\', $class);
class_alias($class, array_pop($parts));
// Make it possible to easily load revisions.
eval(sprintf('class %s extends \%s {
public static function loadRevision($id) {
$entity_type_repository = \Drupal::service("entity_type.repository");
$entity_type_manager = \Drupal::entityTypeManager();
$storage = $entity_type_manager->getStorage($entity_type_repository->getEntityTypeFromClass(static::class));
return $storage->loadRevision($id);
}
}', end($parts), $class));
}
}
}

0 comments on commit 31c64d7

Please sign in to comment.