You are here

public function LingotekLanguageForm::form in Lingotek Translation 8

Same name and namespace in other branches
  1. 8.2 src/Form/LingotekLanguageForm.php \Drupal\lingotek\Form\LingotekLanguageForm::form()
  2. 4.0.x src/Form/LingotekLanguageForm.php \Drupal\lingotek\Form\LingotekLanguageForm::form()
  3. 3.0.x src/Form/LingotekLanguageForm.php \Drupal\lingotek\Form\LingotekLanguageForm::form()
  4. 3.1.x src/Form/LingotekLanguageForm.php \Drupal\lingotek\Form\LingotekLanguageForm::form()
  5. 3.2.x src/Form/LingotekLanguageForm.php \Drupal\lingotek\Form\LingotekLanguageForm::form()
  6. 3.3.x src/Form/LingotekLanguageForm.php \Drupal\lingotek\Form\LingotekLanguageForm::form()
  7. 3.4.x src/Form/LingotekLanguageForm.php \Drupal\lingotek\Form\LingotekLanguageForm::form()
  8. 3.5.x src/Form/LingotekLanguageForm.php \Drupal\lingotek\Form\LingotekLanguageForm::form()
  9. 3.6.x src/Form/LingotekLanguageForm.php \Drupal\lingotek\Form\LingotekLanguageForm::form()
  10. 3.7.x src/Form/LingotekLanguageForm.php \Drupal\lingotek\Form\LingotekLanguageForm::form()
  11. 3.8.x src/Form/LingotekLanguageForm.php \Drupal\lingotek\Form\LingotekLanguageForm::form()

Alters the configurable language entity edit and add form.

Parameters

array $form: The form definition array for the configurable language entity.

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

File

src/Form/LingotekLanguageForm.php, line 55

Class

LingotekLanguageForm
Alters the Drupal language module language forms.

Namespace

Drupal\lingotek\Form

Code

public function form(array &$form, FormStateInterface $form_state) {

  /** @var ConfigurableLanguageInterface $language */
  $language = $form_state
    ->getFormObject()
    ->getEntity();
  $langcode = $language
    ->getId();
  $form['custom_language']['lingotek_locale'] = [
    '#type' => 'textfield',
    '#title' => t('Locale'),
    // If we have a langcode, check if there is a locale or default to the one we can guess.
    '#default_value' => $langcode !== NULL ? str_replace("_", "-", $this->languageLocaleMapper
      ->getLocaleForLangcode($langcode)) : '',
    '#weight' => 0,
    '#description' => $this
      ->t('The Lingotek locale this language maps to.') . ' ' . $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>', array(
      ':w3ctags' => 'http://www.w3.org/International/articles/language-tags/',
    )),
  ];

  // Buttons are different if adding or editing a language. We need validation
  // on both cases.
  if ($langcode) {
    $form['actions']['submit']['#validate'][] = LingotekLanguageForm::class . '::validateLocale';
  }
  else {
    $form['custom_language']['submit']['#validate'][] = LingotekLanguageForm::class . '::validateLocale';
  }
  $form['#entity_builders'][] = LingotekLanguageForm::class . '::languageEntityBuilder';
}