function EntityBase::getTypedDataClass

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Entity/EntityBase.php \Drupal\Core\Entity\EntityBase::getTypedDataClass()
  2. 11.x core/lib/Drupal/Core/Entity/EntityBase.php \Drupal\Core\Entity\EntityBase::getTypedDataClass()

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

1 call to EntityBase::getTypedDataClass()
EntityBase::getTypedData in core/lib/Drupal/Core/Entity/EntityBase.php
Gets a typed data object for this entity object.

File

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

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

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