You are here

public function Language::summary in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/language/src/Plugin/Condition/Language.php \Drupal\language\Plugin\Condition\Language::summary()
  2. 10 core/modules/language/src/Plugin/Condition/Language.php \Drupal\language\Plugin\Condition\Language::summary()

Provides a human readable summary of the condition's configuration.

Overrides ConditionInterface::summary

File

core/modules/language/src/Plugin/Condition/Language.php, line 103

Class

Language
Provides a 'Language' condition.

Namespace

Drupal\language\Plugin\Condition

Code

public function summary() {
  $language_list = $this->languageManager
    ->getLanguages(LanguageInterface::STATE_ALL);
  $selected = $this->configuration['langcodes'];

  // Reduce the language list to an array of language names.
  $language_names = array_reduce($language_list, function (&$result, $item) use ($selected) {

    // If the current item of the $language_list array is one of the selected
    // languages, add it to the $results array.
    if (!empty($selected[$item
      ->getId()])) {
      $result[$item
        ->getId()] = $item
        ->getName();
    }
    return $result;
  }, []);

  // If we have more than one language selected, separate them by commas.
  if (count($this->configuration['langcodes']) > 1) {
    $languages = implode(', ', $language_names);
  }
  else {

    // If we have just one language just grab the only present value.
    $languages = array_pop($language_names);
  }
  if (!empty($this->configuration['negate'])) {
    return t('The language is not @languages.', [
      '@languages' => $languages,
    ]);
  }
  return t('The language is @languages.', [
    '@languages' => $languages,
  ]);
}