You are here

protected function CshsFormatterBase::getTermsLabels in Client-side Hierarchical Select 8

Same name and namespace in other branches
  1. 8.3 src/Plugin/Field/FieldFormatter/CshsFormatterBase.php \Drupal\cshs\Plugin\Field\FieldFormatter\CshsFormatterBase::getTermsLabels()
  2. 8.2 src/Plugin/Field/FieldFormatter/CshsFormatterBase.php \Drupal\cshs\Plugin\Field\FieldFormatter\CshsFormatterBase::getTermsLabels()

Returns the list of terms labels.

Parameters

\Drupal\taxonomy\TermInterface[] $list: The list of terms.

bool $linked: The state of whether to create a linked label.

Return value

string[]|\Drupal\Core\StringTranslation\TranslatableMarkup[] The list of labels.

2 calls to CshsFormatterBase::getTermsLabels()
CshsFullHierarchyFormatter::viewElements in src/Plugin/Field/FieldFormatter/CshsFullHierarchyFormatter.php
Builds a renderable array for a field value.
CshsGroupByRootFormatter::viewElements in src/Plugin/Field/FieldFormatter/CshsGroupByRootFormatter.php
Builds a renderable array for a field value.

File

src/Plugin/Field/FieldFormatter/CshsFormatterBase.php, line 79

Class

CshsFormatterBase
Base formatter for CSHS field.

Namespace

Drupal\cshs\Plugin\Field\FieldFormatter

Code

protected function getTermsLabels(array $list, bool $linked) : array {
  $terms = [];
  foreach ($list as $item) {
    $item = $this
      ->getTranslationFromContext($item);
    $label = $item
      ->label();
    $terms[] = $linked ? $item
      ->toLink($label)
      ->toString() : $label;
  }
  return $terms;
}