You are here

private function EntityBase::getTypedDataClass in Drupal 10

Returns the typed data class name for this entity.

Return value

string The string representing the typed data class name.

See also

\Drupal\Core\Entity\Plugin\DataType\EntityAdapter

File

core/lib/Drupal/Core/Entity/EntityBase.php, line 604

Class

EntityBase
Defines a base entity class.

Namespace

Drupal\Core\Entity

Code

private function getTypedDataClass() : string {
  $typed_data_manager = \Drupal::typedDataManager();

  // Check more specific data types that could apply to this entity.
  $candidate_data_types = [
    "entity:{$this->getEntityTypeId()}:{$this->bundle()}",
    "entity:{$this->getEntityTypeId()}",
  ];
  foreach ($candidate_data_types as $candidate_data_type) {
    if ($typed_data_manager
      ->hasDefinition($candidate_data_type)) {
      return $typed_data_manager
        ->getDefinition($candidate_data_type)['class'];
    }
  }

  // Fall back to the generic entity definition.
  return $typed_data_manager
    ->getDefinition('entity')['class'];
}