function ExportForm::buildForm

Same name and namespace in other branches
  1. 8.9.x core/modules/locale/src/Form/ExportForm.php \Drupal\locale\Form\ExportForm::buildForm()
  2. 10 core/modules/locale/src/Form/ExportForm.php \Drupal\locale\Form\ExportForm::buildForm()
  3. 11.x core/modules/locale/src/Form/ExportForm.php \Drupal\locale\Form\ExportForm::buildForm()

Overrides FormInterface::buildForm

File

core/modules/locale/src/Form/ExportForm.php, line 69

Class

ExportForm
Form for the Gettext translation files export form.

Namespace

Drupal\locale\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
    $languages = $this->languageManager
        ->getLanguages();
    $language_options = [];
    foreach ($languages as $langcode => $language) {
        if (locale_is_translatable($langcode)) {
            $language_options[$langcode] = $language->getName();
        }
    }
    $language_default = $this->languageManager
        ->getDefaultLanguage();
    if (empty($language_options)) {
        $form['langcode'] = [
            '#type' => 'value',
            '#value' => LanguageInterface::LANGCODE_SYSTEM,
        ];
        $form['langcode_text'] = [
            '#type' => 'item',
            '#title' => $this->t('Language'),
            '#markup' => $this->t('No language available. The export will only contain source strings.'),
        ];
    }
    else {
        $form['langcode'] = [
            '#type' => 'select',
            '#title' => $this->t('Language'),
            '#options' => $language_options,
            '#default_value' => $language_default->getId(),
            '#empty_option' => $this->t('Source text only, no translations'),
            '#empty_value' => LanguageInterface::LANGCODE_SYSTEM,
        ];
        $form['content_options'] = [
            '#type' => 'details',
            '#title' => $this->t('Export options'),
            '#tree' => TRUE,
            '#states' => [
                'invisible' => [
                    ':input[name="langcode"]' => [
                        'value' => LanguageInterface::LANGCODE_SYSTEM,
                    ],
                ],
            ],
        ];
        $form['content_options']['not_customized'] = [
            '#type' => 'checkbox',
            '#title' => $this->t('Include non-customized translations'),
            '#default_value' => TRUE,
        ];
        $form['content_options']['customized'] = [
            '#type' => 'checkbox',
            '#title' => $this->t('Include customized translations'),
            '#default_value' => TRUE,
        ];
        $form['content_options']['not_translated'] = [
            '#type' => 'checkbox',
            '#title' => $this->t('Include untranslated text'),
            '#default_value' => TRUE,
        ];
    }
    $form['actions'] = [
        '#type' => 'actions',
    ];
    $form['actions']['submit'] = [
        '#type' => 'submit',
        '#value' => $this->t('Export'),
    ];
    return $form;
}

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