You are here

public static function EntityAutocomplete::getEntityLabels in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Entity/Element/EntityAutocomplete.php \Drupal\Core\Entity\Element\EntityAutocomplete::getEntityLabels()

Converts an array of entity objects into a string of entity labels.

This method is also responsible for checking the 'view' 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.

5 calls to EntityAutocomplete::getEntityLabels()
EntityAutocomplete::valueCallback in core/lib/Drupal/Core/Entity/Element/EntityAutocomplete.php
Determines how user input is mapped to an element's #value property.
EntityAutocompleteElementFormTest::getAutocompleteInput in core/modules/system/src/Tests/Entity/Element/EntityAutocompleteElementFormTest.php
Returns an entity label in the format needed by the EntityAutocomplete element.
LinkWidget::getUriAsDisplayableString in core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php
Gets the URI without the 'internal:' or 'entity:' scheme.
Name::valueForm in core/modules/user/src/Plugin/views/filter/Name.php
Options form subform for setting options.
TaxonomyIndexTid::valueForm in core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php
Options form subform for setting options.

File

core/lib/Drupal/Core/Entity/Element/EntityAutocomplete.php, line 296
Contains \Drupal\Core\Entity\Element\EntityAutocomplete.

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) {
    $label = $entity
      ->access('view') ? $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);
}