You are here

public static function AutocompleteDeluxeWidget::implodeEntities in Autocomplete Deluxe 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/Field/FieldWidget/AutocompleteDeluxeWidget.php \Drupal\autocomplete_deluxe\Plugin\Field\FieldWidget\AutocompleteDeluxeWidget::implodeEntities()

Implodes the tags from the taxonomy module.

Parameters

\Drupal\Core\Entity\EntityInterface[] $entities: List of entities.

string $bundle: Bundle name.

Return value

array Imploded list of entity labels.

1 call to AutocompleteDeluxeWidget::implodeEntities()
AutocompleteDeluxeWidget::formElement in src/Plugin/Field/FieldWidget/AutocompleteDeluxeWidget.php
Returns the form for a single field widget.

File

src/Plugin/Field/FieldWidget/AutocompleteDeluxeWidget.php, line 260

Class

AutocompleteDeluxeWidget
Plugin implementation of the 'options_buttons' widget.

Namespace

Drupal\autocomplete_deluxe\Plugin\Field\FieldWidget

Code

public static function implodeEntities(array $entities, $bundle = NULL) {
  $typed_entities = [];
  foreach ($entities as $entity) {
    $label = $entity
      ->label();

    // Extract entities belonging to the bundle in question.
    if (!isset($bundle) || $entity
      ->bundle() == $bundle) {

      // Make sure we have a completed loaded entity.
      if ($entity && $label) {

        // Commas and quotes in tag names are special cases, so encode 'em.
        if (strpos($label, ',') !== FALSE || strpos($label, '"') !== FALSE) {
          $label = '"' . str_replace('"', '""', $label) . '"';
        }
        $typed_entities[] = $label;
      }
    }
  }
  return implode(',', $typed_entities);
}