public function ConfigureMultilingualForm::buildForm in Varbase: The Ultimate Drupal CMS Starter Kit (Bootstrap Ready) 8.7
Same name and namespace in other branches
- 8.8 src/Form/ConfigureMultilingualForm.php \Drupal\varbase\Form\ConfigureMultilingualForm::buildForm()
- 8.4 src/Form/ConfigureMultilingualForm.php \Drupal\varbase\Form\ConfigureMultilingualForm::buildForm()
- 8.5 src/Form/ConfigureMultilingualForm.php \Drupal\varbase\Form\ConfigureMultilingualForm::buildForm()
- 8.6 src/Form/ConfigureMultilingualForm.php \Drupal\varbase\Form\ConfigureMultilingualForm::buildForm()
- 9.0.x src/Form/ConfigureMultilingualForm.php \Drupal\varbase\Form\ConfigureMultilingualForm::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
- src/
Form/ ConfigureMultilingualForm.php, line 79
Class
- ConfigureMultilingualForm
- Defines form for selecting Varbase's Multiligual configuration options form.
Namespace
Drupal\varbase\FormCode
public function buildForm(array $form, FormStateInterface $form_state, array &$install_state = NULL) {
$standard_languages = LanguageManager::getStandardLanguageList();
$select_options = [];
$browser_options = [];
foreach ($standard_languages as $langcode => $language_names) {
$select_options[$langcode] = $language_names[0];
$browser_options[$langcode] = $langcode;
}
asort($select_options);
$default_langcode = \Drupal::configFactory()
->getEditable('system.site')
->get('default_langcode');
// Save the default language name.
$default_language_name = $select_options[$default_langcode];
// Remove the default language from the list of multilingual languages.
if (isset($select_options[$default_langcode])) {
unset($select_options[$default_langcode]);
}
if (isset($browser_options[$default_langcode])) {
unset($browser_options[$default_langcode]);
}
$form['#title'] = $this
->t('Multilingual configuration');
$form['multilingual_configuration_introduction'] = [
'#weight' => -1,
'#prefix' => '<p>',
'#markup' => '<b>' . $default_language_name . '</b> ' . $this
->t("is the default language."),
'#suffix' => '</p>',
];
$form['enable_multilingual'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable multiple languages for this site'),
'#description' => $this
->t('This will enable the necessary modules for a multilingual website. These include: Language, Interface Translation, Content Translation, Configuration Translation, and its recommended configuration.'),
'#default_value' => FALSE,
];
$form['multilingual_languages'] = [
'#type' => 'select',
'#title' => $this
->t("Please select your site's other language(s)"),
'#description' => $this
->t('You can skip this and add languages later.'),
'#options' => $select_options,
'#multiple' => TRUE,
'#size' => 8,
'#attributes' => [
'style' => 'width:100%;',
],
'#states' => [
'visible' => [
':input[name="enable_multilingual"]' => [
'checked' => TRUE,
],
],
'invisible' => [
':input[name="enable_multilingual"]' => [
'checked' => FALSE,
],
],
],
];
$form['actions'] = [
'continue' => [
'#type' => 'submit',
'#value' => $this
->t('Save and continue'),
'#button_type' => 'primary',
],
'#type' => 'actions',
'#weight' => 5,
];
return $form;
}