function EntityTypeRepository::getEntityTypeFromClass
Same name and namespace in other branches
- 9 core/lib/Drupal/Core/Entity/EntityTypeRepository.php \Drupal\Core\Entity\EntityTypeRepository::getEntityTypeFromClass()
- 10 core/lib/Drupal/Core/Entity/EntityTypeRepository.php \Drupal\Core\Entity\EntityTypeRepository::getEntityTypeFromClass()
- 11.x core/lib/Drupal/Core/Entity/EntityTypeRepository.php \Drupal\Core\Entity\EntityTypeRepository::getEntityTypeFromClass()
Overrides EntityTypeRepositoryInterface::getEntityTypeFromClass
File
-
core/
lib/ Drupal/ Core/ Entity/ EntityTypeRepository.php, line 75
Class
- EntityTypeRepository
- Provides helper methods for loading entity types.
Namespace
Drupal\Core\EntityCode
public function getEntityTypeFromClass($class_name) {
// Check the already calculated classes first.
if (isset($this->classNameEntityTypeMap[$class_name])) {
return $this->classNameEntityTypeMap[$class_name];
}
$same_class = 0;
$entity_type_id = NULL;
foreach ($this->entityTypeManager
->getDefinitions() as $entity_type) {
if ($entity_type->getOriginalClass() == $class_name || $entity_type->getClass() == $class_name) {
$entity_type_id = $entity_type->id();
if ($same_class++) {
throw new AmbiguousEntityClassException($class_name);
}
}
}
// Return the matching entity type ID if there is one.
if ($entity_type_id) {
$this->classNameEntityTypeMap[$class_name] = $entity_type_id;
return $entity_type_id;
}
throw new NoCorrespondingEntityClassException($class_name);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.