You are here

class EckEntityTypeBundleInfo in Entity Construction Kit (ECK) 8

Holds bundle info for eck entity types.

Hierarchy

Expanded class hierarchy of EckEntityTypeBundleInfo

2 files declare their use of EckEntityTypeBundleInfo
EckEntityTypeListBuilder.php in src/Controller/EckEntityTypeListBuilder.php
EntityTypeBundleInfoTest.php in tests/src/Unit/EntityTypeBundleInfoTest.php
1 string reference to 'EckEntityTypeBundleInfo'
eck.services.yml in ./eck.services.yml
eck.services.yml
1 service uses EckEntityTypeBundleInfo
eck.entity_type.bundle.info in ./eck.services.yml
Drupal\eck\EckEntityTypeBundleInfo

File

src/EckEntityTypeBundleInfo.php, line 11

Namespace

Drupal\eck
View source
class EckEntityTypeBundleInfo extends EntityTypeBundleInfo {

  /**
   * {@inheritdoc}
   */
  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;
  }

  /**
   * Determines if a given entity type has bundles.
   *
   * @param string $entity_type
   *   The entity type id.
   *
   * @return bool
   *   Does it have bundles?
   */
  public function entityTypeHasBundles($entity_type) {
    return !empty($this
      ->getBundleInfo($entity_type));
  }

  /**
   * Retrieves the entity type bundle machine names.
   *
   * @param string $entity_type
   *   The entity type id.
   *
   * @return string[]
   *   The entity type bundle machine names.
   */
  public function getEntityTypeBundleMachineNames($entity_type) {
    return array_keys($this
      ->getBundleInfo($entity_type));
  }

  /**
   * The entity type bundle count.
   *
   * @param string $entity_type
   *   The entity type id.
   *
   * @return int
   *   The number of bundles for the given entity type.
   */
  public function entityTypeBundleCount($entity_type) {
    return \count($this
      ->getBundleInfo($entity_type));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EckEntityTypeBundleInfo::entityTypeBundleCount public function The entity type bundle count.
EckEntityTypeBundleInfo::entityTypeHasBundles public function Determines if a given entity type has bundles.
EckEntityTypeBundleInfo::getAllBundleInfo public function Get the bundle info of all entity types. Overrides EntityTypeBundleInfo::getAllBundleInfo
EckEntityTypeBundleInfo::getEntityTypeBundleMachineNames public function Retrieves the entity type bundle machine names.
EntityTypeBundleInfo::$bundleInfo protected property Static cache of bundle information.
EntityTypeBundleInfo::$entityTypeManager protected property The entity type manager.
EntityTypeBundleInfo::$languageManager protected property The language manager.
EntityTypeBundleInfo::$moduleHandler protected property The module handler.
EntityTypeBundleInfo::$typedDataManager protected property The typed data manager.
EntityTypeBundleInfo::clearCachedBundles public function Clears static and persistent bundles. Overrides EntityTypeBundleInfoInterface::clearCachedBundles
EntityTypeBundleInfo::getBundleInfo public function Gets the bundle info of an entity type. Overrides EntityTypeBundleInfoInterface::getBundleInfo
EntityTypeBundleInfo::__construct public function Constructs a new EntityTypeBundleInfo.
UseCacheBackendTrait::$cacheBackend protected property Cache backend instance.
UseCacheBackendTrait::$useCaches protected property Flag whether caches should be used or skipped.
UseCacheBackendTrait::cacheGet protected function Fetches from the cache backend, respecting the use caches flag. 1
UseCacheBackendTrait::cacheSet protected function Stores data in the persistent cache, respecting the use caches flag.