private function OrderEventSubscriber::getOriginalEntity in Commerce Stock 8
Returns the entity from an updated entity object. In certain cases the $entity->original property is empty for updated entities. In such a situation we try to load the unchanged entity from storage.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The changed/updated entity object.
Return value
null|\Drupal\Core\Entity\EntityInterface The original unchanged entity object or NULL.
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
\Drupal\Component\Plugin\Exception\PluginNotFoundException
3 calls to OrderEventSubscriber::getOriginalEntity()
- OrderEventSubscriber::onOrderCancel in src/
EventSubscriber/ OrderEventSubscriber.php - Performs a stock transaction for an order Cancel event.
- OrderEventSubscriber::onOrderItemUpdate in src/
EventSubscriber/ OrderEventSubscriber.php - Performs a stock transaction on an order item update.
- OrderEventSubscriber::onOrderUpdate in src/
EventSubscriber/ OrderEventSubscriber.php - Acts on the order update event to create transactions for new items.
File
- src/
EventSubscriber/ OrderEventSubscriber.php, line 399
Class
- OrderEventSubscriber
- Performs stock transactions on order and order item events.
Namespace
Drupal\commerce_stock\EventSubscriberCode
private function getOriginalEntity(EntityInterface $entity) {
// $entity->original only exists during save. See
// \Drupal\Core\Entity\EntityStorageBase::save().
// If we don't have $entity->original we try to load it.
$original_entity = NULL;
$original_entity = $entity->original;
// @ToDo Consider how this may change due to: ToDo https://www.drupal.org/project/drupal/issues/2839195
if (!$original_entity) {
$id = $entity
->getOriginalId() !== NULL ? $entity
->getOriginalId() : $entity
->id();
$original_entity = $this->entityTypeManager
->getStorage($entity
->getEntityTypeId())
->loadUnchanged($id);
}
return $original_entity;
}