You are here

private function CshsOptionsFromHelper::getTranslatedLevelLabels in Client-side Hierarchical Select 8

Same name and namespace in other branches
  1. 8.3 src/CshsOptionsFromHelper.php \Drupal\cshs\CshsOptionsFromHelper::getTranslatedLevelLabels()
  2. 8.2 src/CshsOptionsFromHelper.php \Drupal\cshs\CshsOptionsFromHelper::getTranslatedLevelLabels()

Returns translated labels with escaped markup.

Parameters

bool $return_as_string: Whether returning value have to be a string.

Return value

string|string[] Translated labels, splitted by comma, or an array of them.

3 calls to CshsOptionsFromHelper::getTranslatedLevelLabels()
CshsOptionsFromHelper::formElement in src/CshsOptionsFromHelper.php
Returns the form for a single widget.
CshsOptionsFromHelper::settingsForm in src/CshsOptionsFromHelper.php
Returns a form to configure settings.
CshsOptionsFromHelper::settingsSummary in src/CshsOptionsFromHelper.php
Returns a short summary for the settings.

File

src/CshsOptionsFromHelper.php, line 351

Class

CshsOptionsFromHelper
Defines a class for getting options for a cshs form element from vocabulary.

Namespace

Drupal\cshs

Code

private function getTranslatedLevelLabels(bool $return_as_string = TRUE) {
  $labels = $this
    ->getSetting('level_labels');
  if (empty($labels)) {
    return $return_as_string ? '' : [];
  }
  $labels = Tags::explode($labels);
  foreach ($labels as $i => $label) {

    // phpcs:ignore Drupal.Semantics.FunctionT.NotLiteralString
    $labels[$i] = $this
      ->t(Html::escape($label));
  }
  return $return_as_string ? \implode(', ', $labels) : $labels;
}