public function LingotekLanguageForm::form in Lingotek Translation 3.8.x
Same name and namespace in other branches
- 8 src/Form/LingotekLanguageForm.php \Drupal\lingotek\Form\LingotekLanguageForm::form()
- 8.2 src/Form/LingotekLanguageForm.php \Drupal\lingotek\Form\LingotekLanguageForm::form()
- 4.0.x src/Form/LingotekLanguageForm.php \Drupal\lingotek\Form\LingotekLanguageForm::form()
- 3.0.x src/Form/LingotekLanguageForm.php \Drupal\lingotek\Form\LingotekLanguageForm::form()
- 3.1.x src/Form/LingotekLanguageForm.php \Drupal\lingotek\Form\LingotekLanguageForm::form()
- 3.2.x src/Form/LingotekLanguageForm.php \Drupal\lingotek\Form\LingotekLanguageForm::form()
- 3.3.x src/Form/LingotekLanguageForm.php \Drupal\lingotek\Form\LingotekLanguageForm::form()
- 3.4.x src/Form/LingotekLanguageForm.php \Drupal\lingotek\Form\LingotekLanguageForm::form()
- 3.5.x src/Form/LingotekLanguageForm.php \Drupal\lingotek\Form\LingotekLanguageForm::form()
- 3.6.x src/Form/LingotekLanguageForm.php \Drupal\lingotek\Form\LingotekLanguageForm::form()
- 3.7.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 73
Class
- LingotekLanguageForm
- Alters the Drupal language module language forms.
Namespace
Drupal\lingotek\FormCode
public function form(array &$form, FormStateInterface $form_state) {
/** @var \Drupal\language\ConfigurableLanguageInterface $language */
$language = $form_state
->getFormObject()
->getEntity();
$langcode = $language
->getId();
$form['custom_language']['lingotek'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Lingotek translation'),
'#weight' => 0,
];
$form['custom_language']['lingotek']['lingotek_disabled'] = [
'#type' => 'checkbox',
'#title' => t('Disabled for Lingotek translation'),
// If we have a langcode, check if there is a locale or default to the one we can guess.
'#default_value' => $langcode !== NULL ? !$this->lingotekConfiguration
->isLanguageEnabled($language) : FALSE,
'#description' => $this
->t('Check this if you want Lingotek to ignore this language or locale.'),
];
$form['custom_language']['lingotek']['lingotek_locale'] = [
'#type' => 'textfield',
'#title' => t('Locale'),
'#autocomplete_route_name' => 'lingotek.supported_locales_autocomplete',
// 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)) : '',
'#description' => $this
->t('The Lingotek locale this language maps to.') . ' ' . $this
->t('Use locale codes as <a href=":w3ctags">defined by the W3C</a> for interoperability. <em>Examples: "en", "en-gb" and "zh-hant".</em>', [
':w3ctags' => 'http://www.w3.org/International/articles/language-tags/',
]),
];
$form['custom_language']['lingotek']['lingotek_locale_link'] = [
'#type' => 'link',
'#title' => $this
->t('Lingotek supported locales list'),
'#url' => Url::fromRoute('lingotek.supported_locales'),
'#ajax' => [
'class' => [
'use-ajax',
],
],
'#attributes' => [
'class' => [
'use-ajax',
],
'data-dialog-type' => 'dialog',
'data-dialog-options' => Json::encode([
'width' => 861,
'height' => 700,
'draggable' => TRUE,
'autoResize' => FALSE,
]),
],
];
// 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';
}