public function ContentEntityStorageBase::getEntityClass in Drupal 10
Retrieves the class name used to create the entity.
Parameters
string|null $bundle: (optional) A specific entity type bundle identifier. Can be omitted in the case of entity types without bundles, like User.
Return value
string The entity class name.
Overrides EntityStorageBase::getEntityClass
3 calls to ContentEntityStorageBase::getEntityClass()
- ContentEntityStorageBase::create in core/
lib/ Drupal/ Core/ Entity/ ContentEntityStorageBase.php - Constructs a new entity object, without permanently saving it.
- ContentEntityStorageBase::doCreate in core/
lib/ Drupal/ Core/ Entity/ ContentEntityStorageBase.php - Performs storage-specific creation of entities.
- SqlContentEntityStorage::mapFromStorageRecords in core/
lib/ Drupal/ Core/ Entity/ Sql/ SqlContentEntityStorage.php - Maps from storage records to entity objects, and attaches fields.
File
- core/
lib/ Drupal/ Core/ Entity/ ContentEntityStorageBase.php, line 196
Class
- ContentEntityStorageBase
- Base class for content entity storage handlers.
Namespace
Drupal\Core\EntityCode
public function getEntityClass(?string $bundle = NULL) : string {
$entity_class = parent::getEntityClass();
// If no bundle is set, use the entity type ID as the bundle ID.
$bundle = $bundle ?? $this
->getEntityTypeId();
// Return the bundle class if it has been defined for this bundle.
$bundle_info = $this->entityTypeBundleInfo
->getBundleInfo($this->entityTypeId);
$bundle_class = $bundle_info[$bundle]['class'] ?? NULL;
// Bundle classes should exist and extend the main entity class.
if ($bundle_class) {
if (!class_exists($bundle_class)) {
throw new MissingBundleClassException($bundle_class);
}
elseif (!is_subclass_of($bundle_class, $entity_class)) {
throw new BundleClassInheritanceException($bundle_class, $entity_class);
}
return $bundle_class;
}
return $entity_class;
}