EckEntityTypeBundleInfo.php in Entity Construction Kit (ECK) 8
File
src/EckEntityTypeBundleInfo.php
View source
<?php
namespace Drupal\eck;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\EntityTypeBundleInfo;
class EckEntityTypeBundleInfo extends EntityTypeBundleInfo {
public function getAllBundleInfo() {
if (empty($this->bundleInfo)) {
$langCode = $this->languageManager
->getCurrentLanguage()
->getId();
if ($cache = $this
->cacheGet("eck_entity_bundle_info:{$langCode}")) {
$this->bundleInfo = $cache->data;
}
else {
$this->bundleInfo = $this->moduleHandler
->invokeAll('entity_bundle_info');
foreach ($this->entityTypeManager
->getDefinitions() as $type => $entity_type) {
if ($bundle_entity_type = $entity_type
->getBundleEntityType()) {
foreach ($this->entityTypeManager
->getStorage($bundle_entity_type)
->loadMultiple() as $entity) {
$this->bundleInfo[$type][$entity
->id()]['label'] = $entity
->label();
}
}
}
$this->moduleHandler
->alter('entity_bundle_info', $this->bundleInfo);
$this
->cacheSet("eck_entity_bundle_info:{$langCode}", $this->bundleInfo, Cache::PERMANENT, [
'entity_types',
'entity_bundles',
]);
}
}
return $this->bundleInfo;
}
public function entityTypeHasBundles($entity_type) {
return !empty($this
->getBundleInfo($entity_type));
}
public function getEntityTypeBundleMachineNames($entity_type) {
return array_keys($this
->getBundleInfo($entity_type));
}
public function entityTypeBundleCount($entity_type) {
return \count($this
->getBundleInfo($entity_type));
}
}