You are here

public function Language::summary in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 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 109
Contains \Drupal\language\Plugin\Condition\Language.

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;
  }, array());

  // 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.', array(
      '@languages' => $languages,
    ));
  }
  return t('The language is @languages.', array(
    '@languages' => $languages,
  ));
}