function EntityTypeRepository::getEntityTypeLabels
Same name and namespace in other branches
- 9 core/lib/Drupal/Core/Entity/EntityTypeRepository.php \Drupal\Core\Entity\EntityTypeRepository::getEntityTypeLabels()
- 10 core/lib/Drupal/Core/Entity/EntityTypeRepository.php \Drupal\Core\Entity\EntityTypeRepository::getEntityTypeLabels()
- 11.x core/lib/Drupal/Core/Entity/EntityTypeRepository.php \Drupal\Core\Entity\EntityTypeRepository::getEntityTypeLabels()
Overrides EntityTypeRepositoryInterface::getEntityTypeLabels
File
-
core/
lib/ Drupal/ Core/ Entity/ EntityTypeRepository.php, line 45
Class
- EntityTypeRepository
- Provides helper methods for loading entity types.
Namespace
Drupal\Core\EntityCode
public function getEntityTypeLabels($group = FALSE) {
$options = [];
$definitions = $this->entityTypeManager
->getDefinitions();
foreach ($definitions as $entity_type_id => $definition) {
if ($group) {
$options[(string) $definition->getGroupLabel()][$entity_type_id] = $definition->getLabel();
}
else {
$options[$entity_type_id] = $definition->getLabel();
}
}
if ($group) {
foreach ($options as &$group_options) {
// Sort the list alphabetically by group label.
array_multisort($group_options, SORT_ASC, SORT_NATURAL);
}
// Make sure that the 'Content' group is situated at the top.
$content = $this->t('Content', [], [
'context' => 'Entity type group',
]);
$options = [
(string) $content => $options[(string) $content],
] + $options;
}
return $options;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.