LanguageSelect.php in YAML Form 8
File
src/Plugin/YamlFormElement/LanguageSelect.php
View source
<?php
namespace Drupal\yamlform\Plugin\YamlFormElement;
use Drupal\yamlform\YamlFormElementBase;
class LanguageSelect extends YamlFormElementBase {
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:
return sprintf('%s (%s)', $language
->getName(), $language
->getId());
}
}
public function getDefaultFormat() {
return 'text';
}
public function getFormats() {
return parent::getFormats() + [
'text' => $this
->t('Text'),
'langcode' => $this
->t('Langcode'),
'language' => $this
->t('Language'),
];
}
}