Skip to content
Snippets Groups Projects
Unverified Commit f293861b authored by Piet de Nooijer's avatar Piet de Nooijer Committed by GitHub
Browse files

Merge pull request #136 from pdenooijer/bugfix/entity_presave

Change EntityPresaveEvent::getOriginalEntity to be nullable
parents 1d3b6c8d 509ba6b5
No related branches found
Tags 8.x-3.5
Loading
......@@ -15,11 +15,11 @@ class EntityPresaveEvent extends AbstractEntityEvent {
*
* @see hook_entity_update()
*
* @return \Drupal\Core\Entity\EntityInterface
* @return \Drupal\Core\Entity\EntityInterface|null
* The original entity.
*/
public function getOriginalEntity(): EntityInterface {
return $this->entity->original;
public function getOriginalEntity(): ?EntityInterface {
return $this->entity->original ?? NULL;
}
/**
......
......@@ -156,6 +156,20 @@ class EntityEventTest extends UnitTestCase {
$this->assertSame($originalEntity, $event->getOriginalEntity());
}
/**
* Test EntityPresaveEvent without original.
*/
public function testEntityPresaveEventWithoutOriginal(): void {
$entity = $this->createMock(EntityInterface::class);
core_event_dispatcher_entity_presave($entity);
/* @var \Drupal\core_event_dispatcher\Event\Entity\EntityPresaveEvent $event */
$event = $this->manager->getRegisteredEvent(HookEventDispatcherInterface::ENTITY_PRE_SAVE);
$this->assertSame($entity, $event->getEntity());
$this->assertNull($event->getOriginalEntity());
}
/**
* Test EntityUpdateEvent.
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment