You are here

public function PurchasableEntityTypeRepositoryInterface::getDefaultPurchasableEntityType in Commerce Core 8.2

Returns a sensible default purchasable entity type.

This is primarily needed to set an entity type to target in the base field definition for the purchasable entity field on order items. The core EntityReferenceItem field definition defaults the base field settings array to specify a target_type of node or user, and it is never overridden by bundle specific settings before the Views module uses that target_type to populate the list of view modes when rendering the purchasable entity reference field value as a "Rendered entity" in Views.

As such, our workaround is to determine a "default" purchasable entity type, privileging commerce_product_variation as the dominant use case if it exists and just selecting the first available entity type if not. Sites that need to set a specific default target_type can still do so by decorating the default service and overriding this method to return your purchasable entity type.

Return value

\Drupal\Core\Entity\EntityTypeInterface The default purchasable entity type definition.

1 method overrides PurchasableEntityTypeRepositoryInterface::getDefaultPurchasableEntityType()
PurchasableEntityTypeRepository::getDefaultPurchasableEntityType in src/PurchasableEntityTypeRepository.php
Returns a sensible default purchasable entity type.

File

src/PurchasableEntityTypeRepositoryInterface.php, line 47

Class

PurchasableEntityTypeRepositoryInterface
Provides an interface for methods to help loading purchasable entity types.

Namespace

Drupal\commerce

Code

public function getDefaultPurchasableEntityType();