You are here

public function LanguageSelect::formatText in YAML Form 8

Format an element's value as plain text.

Parameters

array $element: An element.

array|mixed $value: A value.

array $options: An array of options.

Return value

string The element's value formatted as plain text or a render array.

Overrides YamlFormElementBase::formatText

File

src/Plugin/YamlFormElement/LanguageSelect.php, line 22

Class

LanguageSelect
Provides a 'language_select' element.

Namespace

Drupal\yamlform\Plugin\YamlFormElement

Code

public function formatText(array &$element, $value, array $options = []) {
  $language = \Drupal::languageManager()
    ->getLanguage($value);
  $format = $this
    ->getFormat($element);
  switch ($format) {
    case 'langcode':
      return $language
        ->getId();
    case 'language':
      return $language
        ->getName();
    case 'text':
    default:

      // Use `sprintf` instead of FormattableMarkup because we really just
      // want a basic string.
      return sprintf('%s (%s)', $language
        ->getName(), $language
        ->getId());
  }
}