public function LanguageAddForm::form in Drupal 9
Same name and namespace in other branches
- 8 core/modules/language/src/Form/LanguageAddForm.php \Drupal\language\Form\LanguageAddForm::form()
- 10 core/modules/language/src/Form/LanguageAddForm.php \Drupal\language\Form\LanguageAddForm::form()
Gets the actual form array to be built.
Overrides EntityForm::form
See also
\Drupal\Core\Entity\EntityForm::processForm()
\Drupal\Core\Entity\EntityForm::afterBuild()
File
- core/
modules/ language/ src/ Form/ LanguageAddForm.php, line 29
Class
- LanguageAddForm
- Controller for language addition forms.
Namespace
Drupal\language\FormCode
public function form(array $form, FormStateInterface $form_state) {
$form['#title'] = $this
->t('Add language');
$predefined_languages = $this->languageManager
->getStandardLanguageListWithoutConfigured();
$predefined_languages['custom'] = $this
->t('Custom language...');
$predefined_default = $form_state
->getValue('predefined_langcode', key($predefined_languages));
$form['predefined_langcode'] = [
'#type' => 'select',
'#title' => $this
->t('Language name'),
'#default_value' => $predefined_default,
'#options' => $predefined_languages,
];
$form['predefined_submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Add language'),
'#name' => 'add_language',
'#limit_validation_errors' => [
[
'predefined_langcode',
],
[
'predefined_submit',
],
],
'#states' => [
'invisible' => [
'select#edit-predefined-langcode' => [
'value' => 'custom',
],
],
],
'#validate' => [
'::validatePredefined',
],
'#submit' => [
'::submitForm',
'::save',
],
'#button_type' => 'primary',
];
$custom_language_states_conditions = [
'select#edit-predefined-langcode' => [
'value' => 'custom',
],
];
$form['custom_language'] = [
'#type' => 'container',
'#states' => [
'visible' => $custom_language_states_conditions,
],
];
$this
->commonForm($form['custom_language']);
$form['custom_language']['langcode']['#states'] = [
'required' => $custom_language_states_conditions,
];
$form['custom_language']['label']['#states'] = [
'required' => $custom_language_states_conditions,
];
$form['custom_language']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Add custom language'),
'#name' => 'add_custom_language',
'#validate' => [
'::validateCustom',
],
'#submit' => [
'::submitForm',
'::save',
],
];
return $form;
}