
| Current Path : /var/www/html1/testsite/web/core/modules/views/src/Plugin/views/field/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/html1/testsite/web/core/modules/views/src/Plugin/views/field/LanguageField.php |
<?php
namespace Drupal\views\Plugin\views\field;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\ResultRow;
/**
* Defines a field handler to translate a language into its readable form.
*
* @ingroup views_field_handlers
*
* @ViewsField("language")
*/
class LanguageField extends FieldPluginBase {
/**
* {@inheritdoc}
*/
protected function defineOptions() {
$options = parent::defineOptions();
$options['native_language'] = ['default' => FALSE];
return $options;
}
/**
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form['native_language'] = [
'#title' => $this->t('Display in native language'),
'#type' => 'checkbox',
'#default_value' => $this->options['native_language'],
];
}
/**
* {@inheritdoc}
*/
public function render(ResultRow $values) {
$value = $this->getValue($values);
$languages = $this->options['native_language'] ? \Drupal::languageManager()->getNativeLanguages() : \Drupal::languageManager()->getLanguages();
return isset($languages[$value]) ? $languages[$value]->getName() : '';
}
}