PurchasableEntityTypeRepository.php in Commerce Core 8.2
File
src/PurchasableEntityTypeRepository.php
View source
<?php
namespace Drupal\commerce;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
class PurchasableEntityTypeRepository implements PurchasableEntityTypeRepositoryInterface {
protected $entityTypeManager;
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
public function getPurchasableEntityTypes() {
return array_filter($this->entityTypeManager
->getDefinitions(), static function (EntityTypeInterface $entity_type) {
return $entity_type
->entityClassImplements(PurchasableEntityInterface::class);
});
}
public function getPurchasableEntityTypeLabels() {
return array_map(static function (EntityTypeInterface $entity_type) {
return $entity_type
->getLabel();
}, $this
->getPurchasableEntityTypes());
}
public function getDefaultPurchasableEntityType() {
$purchasable_entity_types = $this
->getPurchasableEntityTypes();
return $purchasable_entity_types['commerce_product_variation'] ?? reset($purchasable_entity_types);
}
}