class GTranslateSettingsForm in Translate Drupal with GTranslate 8
Controller location for Live Weather Settings Form.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
- class \Drupal\gtranslate\Form\GTranslateSettingsForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of GTranslateSettingsForm
1 string reference to 'GTranslateSettingsForm'
File
- src/
Form/ GTranslateSettingsForm.php, line 15 - Contains \Drupal\gtranslate\Form\GTranslateSettingsForm.
Namespace
Drupal\gtranslate\FormView source
class GTranslateSettingsForm extends ConfigFormBase {
protected $languages = array(
'en' => 'English',
'ar' => 'Arabic',
'bg' => 'Bulgarian',
'zh-CN' => 'Chinese (Simplified)',
'zh-TW' => 'Chinese (Traditional)',
'hr' => 'Croatian',
'cs' => 'Czech',
'da' => 'Danish',
'nl' => 'Dutch',
'fi' => 'Finnish',
'fr' => 'French',
'de' => 'German',
'el' => 'Greek',
'hi' => 'Hindi',
'it' => 'Italian',
'ja' => 'Japanese',
'ko' => 'Korean',
'no' => 'Norwegian',
'pl' => 'Polish',
'pt' => 'Portuguese',
'ro' => 'Romanian',
'ru' => 'Russian',
'es' => 'Spanish',
'sv' => 'Swedish',
'ca' => 'Catalan',
'tl' => 'Filipino',
'iw' => 'Hebrew',
'id' => 'Indonesian',
'lv' => 'Latvian',
'lt' => 'Lithuanian',
'sr' => 'Serbian',
'sk' => 'Slovak',
'sl' => 'Slovenian',
'uk' => 'Ukrainian',
'vi' => 'Vietnamese',
'sq' => 'Albanian',
'et' => 'Estonian',
'gl' => 'Galician',
'hu' => 'Hungarian',
'mt' => 'Maltese',
'th' => 'Thai',
'tr' => 'Turkish',
'fa' => 'Persian',
'af' => 'Afrikaans',
'ms' => 'Malay',
'sw' => 'Swahili',
'ga' => 'Irish',
'cy' => 'Welsh',
'be' => 'Belarusian',
'is' => 'Icelandic',
'mk' => 'Macedonian',
'yi' => 'Yiddish',
'hy' => 'Armenian',
'az' => 'Azerbaijani',
'eu' => 'Basque',
'ka' => 'Georgian',
'ht' => 'Haitian Creole',
'ur' => 'Urdu',
'bn' => 'Bengali',
'bs' => 'Bosnian',
'ceb' => 'Cebuano',
'eo' => 'Esperanto',
'gu' => 'Gujarati',
'ha' => 'Hausa',
'hmn' => 'Hmong',
'ig' => 'Igbo',
'jw' => 'Javanese',
'kn' => 'Kannada',
'km' => 'Khmer',
'lo' => 'Lao',
'la' => 'Latin',
'mi' => 'Maori',
'mr' => 'Marathi',
'mn' => 'Mongolian',
'ne' => 'Nepali',
'pa' => 'Punjabi',
'so' => 'Somali',
'ta' => 'Tamil',
'te' => 'Telugu',
'yo' => 'Yoruba',
'zu' => 'Zulu',
'my' => 'Myanmar (Burmese)',
'ny' => 'Chichewa',
'kk' => 'Kazakh',
'mg' => 'Malagasy',
'ml' => 'Malayalam',
'si' => 'Sinhala',
'st' => 'Sesotho',
'su' => 'Sudanese',
'tg' => 'Tajik',
'uz' => 'Uzbek',
'am' => 'Amharic',
'co' => 'Corsican',
'haw' => 'Hawaiian',
'ku' => 'Kurdish (Kurmanji)',
'ky' => 'Kyrgyz',
'lb' => 'Luxembourgish',
'ps' => 'Pashto',
'sm' => 'Samoan',
'gd' => 'Scottish Gaelic',
'sn' => 'Shona',
'sd' => 'Sindhi',
'fy' => 'Frisian',
'xh' => 'Xhosa',
);
/**
* Implements \Drupal\Core\Form\FormInterface::getFormID().
*/
public function getFormId() {
return 'gtranslate_admin';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'gtranslate.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('gtranslate.settings');
$form['general'] = array(
'#type' => 'details',
'#title' => $this
->t('General Configuration'),
'#open' => true,
);
$form['general']['gtranslate_look'] = array(
'#type' => 'select',
'#title' => $this
->t('Look'),
'#default_value' => $config
->get('gtranslate_look'),
'#size' => 1,
'#options' => array(
'flags_dropdown' => 'Flags and dropdown',
'flags' => 'Flags',
'dropdown' => 'Dropdown',
'dropdown_with_flags' => 'Nice dropdown with flags',
),
'#description' => $this
->t("Select the look of the module"),
'#required' => TRUE,
);
$form['general']['gtranslate_main_lang'] = array(
'#type' => 'select',
'#title' => $this
->t('Main Language'),
'#default_value' => $config
->get('gtranslate_main_lang'),
'#size' => 1,
'#options' => $this->languages,
'#description' => $this
->t("Your sites main language"),
'#required' => TRUE,
);
$form['general']['gtranslate_pro'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Sub-directory URL structure'),
'#default_value' => $config
->get('gtranslate_pro'),
'#description' => $this
->t('Example: http://example.com/<b>ru</b>/. This feature is available only in paid plans: <a href="https://gtranslate.io/?xyz=1002#pricing" target="_blank">https://gtranslate.io/#pricing</a>'),
);
$form['general']['gtranslate_enterprise'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Sub-domain URL structure'),
'#default_value' => $config
->get('gtranslate_enterprise'),
'#description' => $this
->t('Example: http://<b>es.</b>example.com/. This feature is available only in paid plans: <a href="https://gtranslate.io/?xyz=1002#pricing" target="_blank">https://gtranslate.io/#pricing</a>'),
);
$form['general']['gtranslate_flag_size'] = array(
'#type' => 'radios',
'#title' => $this
->t('Flag Size'),
'#default_value' => $config
->get('gtranslate_flag_size'),
'#options' => array(
16 => '16px',
24 => '24px',
32 => '32px',
),
'#description' => $this
->t("Select the flag size"),
'#required' => TRUE,
);
$form['general']['gtranslate_new_window'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Open translated page in a new window'),
'#default_value' => $config
->get('gtranslate_new_window'),
'#description' => $this
->t("The translated page will appear in a new window"),
);
$form['general']['gtranslate_analytics'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Analytics'),
'#default_value' => $config
->get('gtranslate_analytics'),
'#description' => $this
->t("If you have Google Analytics _gaq code on your site you can enable this which will allow you to see translation events in Google Analytics -> Content -> Event Tracking."),
);
$form['language'] = array(
'#type' => 'details',
'#title' => $this
->t('Language Configuration'),
);
foreach ($this->languages as $lang => $language) {
$form['language']["gtranslate_{$lang}"] = array(
'#type' => 'radios',
'#title' => $this
->t("Show {$language}"),
'#default_value' => $config
->get('gtranslate_' . $lang, 0),
'#options' => array(
1 => 'Yes',
0 => 'No',
2 => 'As a flag',
),
'#description' => $this
->t("Show {$language} in the language list"),
'#required' => TRUE,
);
}
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$form_value = $form_state
->getValues();
$this
->config('gtranslate.settings')
->set('gtranslate_pro', $form_value['gtranslate_pro'])
->set('gtranslate_enterprise', $form_value['gtranslate_enterprise'])
->set('gtranslate_analytics', $form_value['gtranslate_analytics'])
->set('gtranslate_look', $form_value['gtranslate_look'])
->set('gtranslate_flag_size', $form_value['gtranslate_flag_size'])
->set('gtranslate_new_window', $form_value['gtranslate_new_window'])
->set('gtranslate_main_lang', $form_value['gtranslate_main_lang'])
->save();
foreach ($this->languages as $lang => $language) {
$this
->config('gtranslate.settings')
->set('gtranslate_' . $lang, $form_value['gtranslate_' . $lang])
->save();
}
parent::submitForm($form, $form_state);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFormBase:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
13 |
ConfigFormBase:: |
public | function | Constructs a \Drupal\system\ConfigFormBase object. | 11 |
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
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 | 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. | |
GTranslateSettingsForm:: |
protected | property | ||
GTranslateSettingsForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
GTranslateSettingsForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
GTranslateSettingsForm:: |
public | function |
Implements \Drupal\Core\Form\FormInterface::getFormID(). Overrides FormInterface:: |
|
GTranslateSettingsForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
GTranslateSettingsForm:: |
public | function |
Form validation handler. Overrides FormBase:: |
|
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. |