ExportForm::buildForm

public ExportForm::buildForm(array $form, FormStateInterface $form_state)

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 55

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 = array();
  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'] = array(
      '#type' => 'value',
      '#value' => LanguageInterface::LANGCODE_SYSTEM,
    );
    $form['langcode_text'] = array(
      '#type' => 'item',
      '#title' => $this->t('Language'),
      '#markup' => $this->t('No language available. The export will only contain source strings.'),
    );
  }
  else {
    $form['langcode'] = array(
      '#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'] = array(
      '#type' => 'details',
      '#title' => $this->t('Export options'),
      '#collapsed' => TRUE,
      '#tree' => TRUE,
      '#states' => array(
        'invisible' => array(
          ':input[name="langcode"]' => array('value' => LanguageInterface::LANGCODE_SYSTEM),
        ),
      ),
    );
    $form['content_options']['not_customized'] = array(
      '#type' => 'checkbox',
      '#title' => $this->t('Include non-customized translations'),
      '#default_value' => TRUE,
    );
    $form['content_options']['customized'] = array(
      '#type' => 'checkbox',
      '#title' => $this->t('Include customized translations'),
      '#default_value' => TRUE,
    );
    $form['content_options']['not_translated'] = array(
      '#type' => 'checkbox',
      '#title' => $this->t('Include untranslated text'),
      '#default_value' => TRUE,
    );
  }

  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => $this->t('Export'),
  );
  return $form;
}
doc_Drupal
2016-10-29 09:09:35
Comments
Leave a Comment

Please login to continue.