function ContentEntityStorageBase::getBundleFromClass

Same name in other branches
  1. 10 core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php \Drupal\Core\Entity\ContentEntityStorageBase::getBundleFromClass()
  2. 11.x core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php \Drupal\Core\Entity\ContentEntityStorageBase::getBundleFromClass()

Overrides BundleEntityStorageInterface::getBundleFromClass

File

core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php, line 136

Class

ContentEntityStorageBase
Base class for content entity storage handlers.

Namespace

Drupal\Core\Entity

Code

public function getBundleFromClass(string $class_name) : ?string {
    $bundle_for_class = NULL;
    foreach ($this->entityTypeBundleInfo
        ->getBundleInfo($this->entityTypeId) as $bundle => $bundle_info) {
        if (!empty($bundle_info['class']) && $bundle_info['class'] === $class_name) {
            if ($bundle_for_class) {
                throw new AmbiguousBundleClassException($class_name);
            }
            else {
                $bundle_for_class = $bundle;
            }
        }
    }
    return $bundle_for_class;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.