class LanguageField in Drupal 10
Same name and namespace in other branches
- 8 core/modules/views/src/Plugin/views/field/LanguageField.php \Drupal\views\Plugin\views\field\LanguageField
- 9 core/modules/views/src/Plugin/views/field/LanguageField.php \Drupal\views\Plugin\views\field\LanguageField
Defines a field handler to translate a language into its readable form.
Plugin annotation
@ViewsField("language");
Hierarchy
- class \Drupal\views\Plugin\views\field\LanguageField extends \Drupal\views\Plugin\views\field\FieldPluginBase
Expanded class hierarchy of LanguageField
File
- core/
modules/ views/ src/ Plugin/ views/ field/ LanguageField.php, line 15
Namespace
Drupal\views\Plugin\views\fieldView source
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() : '';
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LanguageField:: |
public | function | ||
LanguageField:: |
protected | function | ||
LanguageField:: |
public | function |