function LanguageFormBase::commonForm

Same name in other branches
  1. 9 core/modules/language/src/Form/LanguageFormBase.php \Drupal\language\Form\LanguageFormBase::commonForm()
  2. 8.9.x core/modules/language/src/Form/LanguageFormBase.php \Drupal\language\Form\LanguageFormBase::commonForm()
  3. 11.x core/modules/language/src/Form/LanguageFormBase.php \Drupal\language\Form\LanguageFormBase::commonForm()

Common elements of the language addition and editing form.

2 calls to LanguageFormBase::commonForm()
LanguageAddForm::form in core/modules/language/src/Form/LanguageAddForm.php
Gets the actual form array to be built.
LanguageEditForm::form in core/modules/language/src/Form/LanguageEditForm.php
Gets the actual form array to be built.

File

core/modules/language/src/Form/LanguageFormBase.php, line 46

Class

LanguageFormBase
Base form for language add and edit forms.

Namespace

Drupal\language\Form

Code

public function commonForm(array &$form) {
    
    /** @var \Drupal\language\ConfigurableLanguageInterface $language */
    $language = $this->entity;
    if ($language->getId()) {
        $form['langcode_view'] = [
            '#type' => 'item',
            '#title' => $this->t('Language code'),
            '#markup' => $language->id(),
        ];
        $form['langcode'] = [
            '#type' => 'value',
            '#value' => $language->id(),
        ];
    }
    else {
        $form['langcode'] = [
            '#type' => 'textfield',
            '#title' => $this->t('Language code'),
            '#maxlength' => 12,
            '#required' => TRUE,
            '#default_value' => '',
            '#disabled' => FALSE,
            '#description' => $this->t('Use language codes as <a href=":w3ctags">defined by the W3C</a> for interoperability. <em>Examples: "en", "en-gb" and "zh-hant".</em>', [
                ':w3ctags' => 'http://www.w3.org/International/articles/language-tags/',
            ]),
        ];
    }
    $form['label'] = [
        '#type' => 'textfield',
        '#title' => $this->t('Language name'),
        '#maxlength' => 64,
        '#default_value' => $language->label(),
        '#required' => TRUE,
    ];
    $form['direction'] = [
        '#type' => 'radios',
        '#title' => $this->t('Direction'),
        '#required' => TRUE,
        '#description' => $this->t('Direction that text in this language is presented.'),
        '#default_value' => $language->getDirection(),
        '#options' => [
            LanguageInterface::DIRECTION_LTR => $this->t('Left to right'),
            LanguageInterface::DIRECTION_RTL => $this->t('Right to left'),
        ],
    ];
    return $form;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.