function ContentEntityStorageBase::getBundleFromClass

Same name and namespace in other branches
  1. 9 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()

Retrieves the bundle name for a provided class name.

Parameters

string $class_name: The class name to check.

Return value

string|null The bundle name of the class provided or NULL if unable to determine the bundle from the provided class.

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.