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\Element
Code
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); }
Please login to continue.