function ContentEntityStorageBase::getEntityClass

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

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 193

Class

ContentEntityStorageBase
Base class for content entity storage handlers.

Namespace

Drupal\Core\Entity

Code

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;
}

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