You are here

protected function PromotionOfferBase::assertEntity in Commerce Core 8.2

Asserts that the given entity is of the expected type.

Parameters

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

6 calls to PromotionOfferBase::assertEntity()
BuyXGetY::apply in modules/promotion/src/Plugin/Commerce/PromotionOffer/BuyXGetY.php
Applies the offer to the given entity.
BuyXGetY::clear in modules/promotion/src/Plugin/Commerce/PromotionOffer/BuyXGetY.php
Allows an offer to clean up any modifications done to the given entity.
OrderFixedAmountOff::apply in modules/promotion/src/Plugin/Commerce/PromotionOffer/OrderFixedAmountOff.php
Applies the offer to the given entity.
OrderItemFixedAmountOff::apply in modules/promotion/src/Plugin/Commerce/PromotionOffer/OrderItemFixedAmountOff.php
Applies the offer to the given entity.
OrderItemPercentageOff::apply in modules/promotion/src/Plugin/Commerce/PromotionOffer/OrderItemPercentageOff.php
Applies the offer to the given entity.

... See full list

File

modules/promotion/src/Plugin/Commerce/PromotionOffer/PromotionOfferBase.php, line 123

Class

PromotionOfferBase
Provides the base class for offers.

Namespace

Drupal\commerce_promotion\Plugin\Commerce\PromotionOffer

Code

protected function assertEntity(EntityInterface $entity) {
  $entity_type_id = $entity
    ->getEntityTypeId();
  $offer_entity_type_id = $this
    ->getEntityTypeId();
  if ($entity_type_id != $offer_entity_type_id) {
    throw new \InvalidArgumentException(sprintf('The offer requires a "%s" entity, but a "%s" entity was given.', $offer_entity_type_id, $entity_type_id));
  }
}