On this page
public static function EntityAutocomplete::getEntityLabels
public static EntityAutocomplete::getEntityLabels(array $entities)
Converts an array of entity objects into a string of entity labels.
This method is also responsible for checking the 'view label' access on the passed-in entities.
Parameters
\Drupal\Core\Entity\EntityInterface[] $entities: An array of entity objects.
Return value
string A string of entity labels separated by commas.
File
- core/lib/Drupal/Core/Entity/Element/EntityAutocomplete.php, line 320
Class
- EntityAutocomplete
- Provides an entity autocomplete form element.
Namespace
Drupal\Core\Entity\ElementCode
public static function getEntityLabels(array $entities) {
$entity_labels = array();
foreach ($entities as $entity) {
// Use the special view label, since some entities allow the label to be
// viewed, even if the entity is not allowed to be viewed.
$label = ($entity->access('view label')) ? $entity->label() : t('- Restricted access -');
// Take into account "autocreated" entities.
if (!$entity->isNew()) {
$label .= ' (' . $entity->id() . ')';
}
// Labels containing commas or quotes must be wrapped in quotes.
$entity_labels[] = Tags::encode($label);
}
return implode(', ', $entity_labels);
}
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!Element!EntityAutocomplete.php/function/EntityAutocomplete::getEntityLabels/8.1.x