class ConfigureMultilingualForm in Varbase: The Ultimate Drupal CMS Starter Kit (Bootstrap Ready) 8.4
Same name and namespace in other branches
- 8.8 src/Form/ConfigureMultilingualForm.php \Drupal\varbase\Form\ConfigureMultilingualForm
- 8.5 src/Form/ConfigureMultilingualForm.php \Drupal\varbase\Form\ConfigureMultilingualForm
- 8.6 src/Form/ConfigureMultilingualForm.php \Drupal\varbase\Form\ConfigureMultilingualForm
- 8.7 src/Form/ConfigureMultilingualForm.php \Drupal\varbase\Form\ConfigureMultilingualForm
- 9.0.x src/Form/ConfigureMultilingualForm.php \Drupal\varbase\Form\ConfigureMultilingualForm
Defines form for selecting Varbase's Multiligual configuration options form.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\varbase\Form\ConfigureMultilingualForm
Expanded class hierarchy of ConfigureMultilingualForm
1 file declares its use of ConfigureMultilingualForm
- varbase.profile in ./
varbase.profile - Enables modules and site configuration for a Varbase site installation.
File
- src/
Form/ ConfigureMultilingualForm.php, line 15
Namespace
Drupal\varbase\FormView source
class ConfigureMultilingualForm extends FormBase {
/**
* The Drupal application root.
*
* @var string
*/
protected $root;
/**
* The info parser service.
*
* @var \Drupal\Core\Extension\InfoParserInterface
*/
protected $infoParser;
/**
* The form helper.
*
* @var \Drupal\varbase\AssemblerFormHelper
*/
protected $formHelper;
/**
* Configure Multilingual Form constructor.
*
* @param string $root
* The Drupal application root.
* @param InfoParserInterface $info_parser
* The info parser service.
* @param TranslationInterface $translator
* The string translation service.
* @param \Drupal\varbase\Form\FormHelper $form_helper
* The form helper.
*/
public function __construct($root, InfoParserInterface $info_parser, TranslationInterface $translator, FormHelper $form_helper) {
$this->root = $root;
$this->infoParser = $info_parser;
$this->stringTranslation = $translator;
$this->formHelper = $form_helper;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('app.root'), $container
->get('info_parser'), $container
->get('string_translation'), $container
->get('varbase.form_helper'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'varbase_multilingual_configuration';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, array &$install_state = NULL) {
$standard_languages = LanguageManager::getStandardLanguageList();
$select_options = array();
$browser_options = array();
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'] = array(
'#weight' => -1,
'#prefix' => '<p>',
'#markup' => '<b>' . $default_language_name . '</b> ' . $this
->t("is the default language."),
'#suffix' => '</p>',
);
$form['enable_multilingual'] = array(
'#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'] = array(
'#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' => array(
'style' => 'width:100%;',
),
'#states' => array(
'visible' => array(
':input[name="enable_multilingual"]' => array(
'checked' => TRUE,
),
),
'invisible' => array(
':input[name="enable_multilingual"]' => array(
'checked' => FALSE,
),
),
),
);
$form['actions'] = [
'continue' => [
'#type' => 'submit',
'#value' => $this
->t('Save and continue'),
'#button_type' => 'primary',
],
'#type' => 'actions',
'#weight' => 5,
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// Get the value of enable multilingual checkbox.
$enable_multilingual = $form_state
->getValue('enable_multilingual');
if (isset($enable_multilingual) && $enable_multilingual == TRUE) {
$GLOBALS['install_state']['varbase']['enable_multilingual'] = TRUE;
}
else {
$GLOBALS['install_state']['varbase']['enable_multilingual'] = FALSE;
}
// Get list of selected multilingual languages.
$multilingual_languages = $form_state
->getValue('multilingual_languages');
if (isset($multilingual_languages) && count($multilingual_languages) > 0) {
$multilingual_languages = array_filter($multilingual_languages);
}
else {
$multilingual_languages = [];
}
$GLOBALS['install_state']['varbase']['multilingual_languages'] = $multilingual_languages;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigureMultilingualForm:: |
protected | property | The form helper. | |
ConfigureMultilingualForm:: |
protected | property | The info parser service. | |
ConfigureMultilingualForm:: |
protected | property | The Drupal application root. | |
ConfigureMultilingualForm:: |
public | function |
Form constructor. Overrides FormInterface:: |
|
ConfigureMultilingualForm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
ConfigureMultilingualForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
ConfigureMultilingualForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
ConfigureMultilingualForm:: |
public | function | Configure Multilingual Form constructor. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
62 |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |