public EntityTypeRepository::getEntityTypeLabels($group = FALSE)
Builds a list of entity type labels suitable for a Form API options list.
Parameters
bool $group: (optional) Whether to group entity types by plugin group (e.g. 'content', 'config'). Defaults to FALSE.
Return value
array An array of entity type labels, keyed by entity type name.
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\Entity
Code
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', array(), array('context' => 'Entity type group'));
$options = array((string) $content => $options[(string) $content]) + $options;
}
return $options;
}
Please login to continue.