public function ContentEntityStorageBase::getBundleFromClass in Drupal 10
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.
Throws
\Drupal\Core\Entity\Exception\AmbiguousBundleClassException Thrown when multiple bundles are using 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\EntityCode
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;
}