function FormTestLanguageSelectForm::buildForm

Same name in other branches
  1. 9 core/modules/system/tests/modules/form_test/src/Form/FormTestLanguageSelectForm.php \Drupal\form_test\Form\FormTestLanguageSelectForm::buildForm()
  2. 10 core/modules/system/tests/modules/form_test/src/Form/FormTestLanguageSelectForm.php \Drupal\form_test\Form\FormTestLanguageSelectForm::buildForm()
  3. 11.x core/modules/system/tests/modules/form_test/src/Form/FormTestLanguageSelectForm.php \Drupal\form_test\Form\FormTestLanguageSelectForm::buildForm()

Overrides FormInterface::buildForm

File

core/modules/system/tests/modules/form_test/src/Form/FormTestLanguageSelectForm.php, line 27

Class

FormTestLanguageSelectForm
Builds a form to test the language select form element.

Namespace

Drupal\form_test\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
    $form['languages_all'] = [
        '#title' => t('Languages: All'),
        '#type' => 'language_select',
        '#languages' => LanguageInterface::STATE_ALL,
        '#default_value' => 'xx',
    ];
    $form['languages_configurable'] = [
        '#title' => t('Languages: Configurable'),
        '#type' => 'language_select',
        '#languages' => LanguageInterface::STATE_CONFIGURABLE,
        '#default_value' => 'en',
    ];
    $form['languages_locked'] = [
        '#title' => t('Languages: Locked'),
        '#type' => 'language_select',
        '#languages' => LanguageInterface::STATE_LOCKED,
    ];
    $form['languages_config_and_locked'] = [
        '#title' => t('Languages: Configurable and locked'),
        '#type' => 'language_select',
        '#languages' => LanguageInterface::STATE_CONFIGURABLE | LanguageInterface::STATE_LOCKED,
        '#default_value' => 'dummy_value',
    ];
    $form['language_custom_options'] = [
        '#title' => t('Languages: Custom'),
        '#type' => 'language_select',
        '#languages' => LanguageInterface::STATE_CONFIGURABLE | LanguageInterface::STATE_LOCKED,
        '#options' => [
            'opt1' => 'First option',
            'opt2' => 'Second option',
            'opt3' => 'Third option',
        ],
        '#default_value' => 'opt2',
    ];
    $form['submit'] = [
        '#type' => 'submit',
        '#value' => 'Submit',
    ];
    return $form;
}

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