You are here

public function ExportForm::buildForm in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/locale/src/Form/ExportForm.php \Drupal\locale\Form\ExportForm::buildForm()

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

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;
}