You are here

public static function EntityAutocomplete::getEntityLabels in Open Social 8.9

Same name and namespace in other branches
  1. 8 modules/social_features/social_core/src/Entity/Element/EntityAutocomplete.php \Drupal\social_core\Entity\Element\EntityAutocomplete::getEntityLabels()
  2. 8.2 modules/social_features/social_core/src/Entity/Element/EntityAutocomplete.php \Drupal\social_core\Entity\Element\EntityAutocomplete::getEntityLabels()
  3. 8.3 modules/social_features/social_core/src/Entity/Element/EntityAutocomplete.php \Drupal\social_core\Entity\Element\EntityAutocomplete::getEntityLabels()
  4. 8.4 modules/social_features/social_core/src/Entity/Element/EntityAutocomplete.php \Drupal\social_core\Entity\Element\EntityAutocomplete::getEntityLabels()
  5. 8.5 modules/social_features/social_core/src/Entity/Element/EntityAutocomplete.php \Drupal\social_core\Entity\Element\EntityAutocomplete::getEntityLabels()
  6. 8.6 modules/social_features/social_core/src/Entity/Element/EntityAutocomplete.php \Drupal\social_core\Entity\Element\EntityAutocomplete::getEntityLabels()
  7. 8.7 modules/social_features/social_core/src/Entity/Element/EntityAutocomplete.php \Drupal\social_core\Entity\Element\EntityAutocomplete::getEntityLabels()
  8. 8.8 modules/social_features/social_core/src/Entity/Element/EntityAutocomplete.php \Drupal\social_core\Entity\Element\EntityAutocomplete::getEntityLabels()
  9. 10.3.x modules/social_features/social_core/src/Entity/Element/EntityAutocomplete.php \Drupal\social_core\Entity\Element\EntityAutocomplete::getEntityLabels()
  10. 10.0.x modules/social_features/social_core/src/Entity/Element/EntityAutocomplete.php \Drupal\social_core\Entity\Element\EntityAutocomplete::getEntityLabels()
  11. 10.1.x modules/social_features/social_core/src/Entity/Element/EntityAutocomplete.php \Drupal\social_core\Entity\Element\EntityAutocomplete::getEntityLabels()
  12. 10.2.x modules/social_features/social_core/src/Entity/Element/EntityAutocomplete.php \Drupal\social_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 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.

Overrides EntityAutocomplete::getEntityLabels

1 call to EntityAutocomplete::getEntityLabels()
EntityAutocomplete::valueCallback in modules/social_features/social_core/src/Entity/Element/EntityAutocomplete.php
Determines how user input is mapped to an element's #value property.

File

modules/social_features/social_core/src/Entity/Element/EntityAutocomplete.php, line 23

Class

EntityAutocomplete
Provides an entity autocomplete form element.

Namespace

Drupal\social_core\Entity\Element

Code

public static function getEntityLabels(array $entities, $hide_id = FALSE) {
  $entity_labels = [];
  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() && !$hide_id) {
      $label .= ' (' . $entity
        ->id() . ')';
    }

    // Labels containing commas or quotes must be wrapped in quotes.
    $entity_labels[] = Tags::encode($label);
  }
  return implode(', ', $entity_labels);
}