class SettingsForm in Browser update 8
Defines a form that configures browser-update.org settings.
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\bu\Form\SettingsForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of SettingsForm
1 string reference to 'SettingsForm'
File
- src/
Form/ SettingsForm.php, line 12
Namespace
Drupal\bu\FormView source
class SettingsForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'bu_admin_settings_form';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'bu.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
// Get current settings.
$bu_config = $this
->config('bu.settings');
$form['information'] = [
'#type' => 'container',
'#attributes' => [],
'#children' => $this
->t('These are the settings which determine how the browser-update.org update notification displays. You can test this notification by appending #test-bu to the end of any URL. For example, @homepageTest', [
'@homepageTest' => Link::createFromRoute($this
->t('click here to test the notification on the homepage'), '<front>', [], [
'fragment' => 'test-bu',
])
->toString(),
]),
];
// Set which versions receive the popup.
$form['notify'] = [
'#type' => 'details',
'#open' => TRUE,
'#title' => $this
->t('Browser Versions'),
'#description' => $this
->t('Choose which of the following browser versions will see the notification:'),
'notify_ie' => [
'#type' => 'select',
'#title' => $this
->t('IE/Edge'),
'#options' => [
'-0.01' => $this
->t('Every outdated version'),
'15' => $this
->t('<= 15'),
'14' => $this
->t('<= 14'),
'13' => $this
->t('<= 13'),
'12' => $this
->t('<= 12'),
'11' => $this
->t('<= 11'),
'10' => $this
->t('<= 10'),
'-6' => $this
->t('more than 6 versions behind'),
'-5' => $this
->t('more than 5 versions behind'),
'-4' => $this
->t('more than 4 versions behind'),
'-3' => $this
->t('more than 3 versions behind'),
'-2' => $this
->t('more than 2 versions behind'),
'-1' => $this
->t('more than 1 versions behind'),
],
'#default_value' => $bu_config
->get('notify_ie'),
],
'notify_firefox' => [
'#type' => 'select',
'#title' => $this
->t('Firefox'),
'#options' => [
'-0.01' => $this
->t('Every outdated version'),
'57' => $this
->t('<= 57'),
'56' => $this
->t('<= 56'),
'55' => $this
->t('<= 55'),
'54' => $this
->t('<= 54'),
'53' => $this
->t('<= 53'),
'52' => $this
->t('<= 52'),
'-6' => $this
->t('more than 6 versions behind'),
'-5' => $this
->t('more than 5 versions behind'),
'-4' => $this
->t('more than 4 versions behind'),
'-3' => $this
->t('more than 3 versions behind'),
'-2' => $this
->t('more than 2 versions behind'),
'-1' => $this
->t('more than 1 versions behind'),
],
'#default_value' => $bu_config
->get('notify_firefox'),
],
'notify_opera' => [
'#type' => 'select',
'#title' => $this
->t('Opera'),
'#options' => [
'-0.01' => $this
->t('Every outdated version'),
'50' => $this
->t('<= 50'),
'49' => $this
->t('<= 49'),
'48' => $this
->t('<= 48'),
'47' => $this
->t('<= 47'),
'46' => $this
->t('<= 46'),
'45' => $this
->t('<= 45'),
'-6' => $this
->t('more than 6 versions behind'),
'-5' => $this
->t('more than 5 versions behind'),
'-4' => $this
->t('more than 4 versions behind'),
'-3' => $this
->t('more than 3 versions behind'),
'-2' => $this
->t('more than 2 versions behind'),
'-1' => $this
->t('more than 1 versions behind'),
],
'#default_value' => $bu_config
->get('notify_opera'),
],
'notify_safari' => [
'#type' => 'select',
'#title' => $this
->t('Safari'),
'#options' => [
'-0.01' => $this
->t('Every outdated version'),
'10' => $this
->t('<= 10'),
'9' => $this
->t('<= 9'),
'8' => $this
->t('<= 8'),
'7' => $this
->t('<= 7'),
'6' => $this
->t('<= 6'),
'5' => $this
->t('<= 5'),
'-6' => $this
->t('more than 6 versions behind'),
'-5' => $this
->t('more than 5 versions behind'),
'-4' => $this
->t('more than 4 versions behind'),
'-3' => $this
->t('more than 3 versions behind'),
'-2' => $this
->t('more than 2 versions behind'),
'-1' => $this
->t('more than 1 versions behind'),
],
'#default_value' => $bu_config
->get('notify_safari'),
],
'notify_chrome' => [
'#type' => 'select',
'#title' => $this
->t('Chrome'),
'#options' => [
'-0.01' => $this
->t('Every outdated version'),
'63' => $this
->t('<= 63'),
'62' => $this
->t('<= 62'),
'61' => $this
->t('<= 61'),
'60' => $this
->t('<= 60'),
'59' => $this
->t('<= 59'),
'58' => $this
->t('<= 58'),
'-6' => $this
->t('more than 6 versions behind'),
'-5' => $this
->t('more than 5 versions behind'),
'-4' => $this
->t('more than 4 versions behind'),
'-3' => $this
->t('more than 3 versions behind'),
'-2' => $this
->t('more than 2 versions behind'),
'-1' => $this
->t('more than 1 versions behind'),
],
'#default_value' => $bu_config
->get('notify_chrome'),
],
'insecure' => [
'#type' => 'checkbox',
'#title' => $this
->t('Notify all browser versions with severe security issues.'),
'#default_value' => $bu_config
->get('insecure'),
],
'unsupported' => [
'#type' => 'checkbox',
'#title' => $this
->t('Also notify all browsers that are not supported by the vendor anymore.'),
'#default_value' => $bu_config
->get('unsupported'),
],
'mobile' => [
'#type' => 'checkbox',
'#title' => $this
->t('Notify mobile browsers.'),
'#default_value' => $bu_config
->get('mobile'),
],
];
// Set visibility for the popup.
$form['visibility'] = [
'#type' => 'details',
'#open' => FALSE,
'#title' => $this
->t('Visibility'),
'#description' => $this
->t('Specify pages by using their paths. Enter one path per line. The "*" character is a wildcard. An example path is /user/* for every user page. <front> is the front page.'),
'visibility_pages' => [
'#type' => 'textarea',
'#title' => $this
->t('Pages'),
'#default_value' => $bu_config
->get('visibility_pages'),
],
'visibility_type' => [
'#type' => 'radios',
'#options' => [
'show' => $this
->t('Show for the listed pages'),
'hide' => $this
->t('Hide for the listed pages'),
],
'#default_value' => $bu_config
->get('visibility_type'),
],
];
// Additional settings.
$form['additional'] = [
'#type' => 'details',
'#open' => FALSE,
'#title' => $this
->t('Additional Settings'),
'source' => [
'#type' => 'url',
'#title' => $this
->t('Source File (base)'),
'#description' => $this
->t('This can be used to override the source file for the update script to point elsewhere. By default, the script is located at %url. Leave this setting blank to use the default.', [
'%url' => '//browser-update.org/update.min.js',
]),
'#default_value' => $bu_config
->get('source'),
],
'show_source' => [
'#type' => 'url',
'#title' => $this
->t('Source File (display)'),
'#description' => $this
->t('This can be used to override the source file for the script which shows the notification. This is only loaded if the user actually has an outdated browser. By default, the script is located at %url. Leave this setting blank to use the default.', [
'%url' => '//browser-update.org/update.show.min.js',
]),
'#default_value' => $bu_config
->get('show_source'),
],
'position' => [
'#type' => 'select',
'#title' => $this
->t('Position'),
'#description' => $this
->t('Set the display location of the message.'),
'#options' => [
'top' => $this
->t('Top'),
'bottom' => $this
->t('Bottom'),
'corner' => $this
->t('Corner'),
],
'#default_value' => $bu_config
->get('position'),
],
'text_override' => [
'#type' => 'textarea',
'#title' => $this
->t('Message Text Override'),
'#description' => $this
->t('Placeholders can be used here. {brow_name} will be replaced with the browser name, {up_but} with contents of the update link tag and {ignore_but} with contents for the ignore link. Example: %example.', [
'%example' => 'Your browser, {brow_name}, is too old: <a{up_but}>update</a> or <a{ignore_but}>ignore</a>',
]),
'#default_value' => $bu_config
->get('text_override'),
],
'reminder' => [
'#type' => 'number',
'#title' => $this
->t('Reminder (in hours)'),
'#description' => $this
->t('Set after how many hours the message should reappear. A value of 0 means "show all the time".'),
'#min' => 0,
'#step' => 1,
'#default_value' => $bu_config
->get('reminder'),
],
'reminder_closed' => [
'#type' => 'number',
'#title' => $this
->t('Reminder after closing (in hours)'),
'#description' => $this
->t('Set after how many hours the message should reappear if the user explicity closes it.'),
'#min' => 0,
'#step' => 1,
'#default_value' => $bu_config
->get('reminder_closed'),
],
'new_window' => [
'#type' => 'checkbox',
'#title' => $this
->t('Open link in new window'),
'#description' => $this
->t('Setting this checkbox will cause the browser update link to open in a new window.'),
'#default_value' => $bu_config
->get('new_window'),
],
'url' => [
'#type' => 'url',
'#title' => $this
->t('Destination URL'),
'#description' => $this
->t('Setting this will set the URL that the user is sent to when they click the notification.'),
'#default_value' => $bu_config
->get('url'),
],
'no_close' => [
'#type' => 'checkbox',
'#title' => $this
->t('Hide Ignore Button'),
'#description' => $this
->t('Setting this checkbox will cause the "ignore" button to be hidden on the notification.'),
'#default_value' => $bu_config
->get('no_close'),
],
];
// Test mode - display all the time.
$form['test_mode'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Test Mode'),
'#description' => $this
->t('Setting this checkbox will cause the message to be displayed all the time (for testing purposes).'),
'#default_value' => $bu_config
->get('test_mode'),
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValues();
// Save the updated settings.
$this
->config('bu.settings')
->set('notify_ie', $values['notify_ie'])
->set('notify_firefox', $values['notify_firefox'])
->set('notify_opera', $values['notify_opera'])
->set('notify_safari', $values['notify_safari'])
->set('notify_chrome', $values['notify_chrome'])
->set('insecure', $values['insecure'])
->set('unsupported', $values['unsupported'])
->set('mobile', $values['mobile'])
->set('position', $values['position'])
->set('visibility_pages', $values['visibility_pages'])
->set('visibility_type', $values['visibility_type'])
->set('text_override', $values['text_override'])
->set('reminder', $values['reminder'])
->set('reminder_closed', $values['reminder_closed'])
->set('test_mode', $values['test_mode'])
->set('new_window', $values['new_window'])
->set('url', $values['url'])
->set('no_close', $values['no_close'])
->set('source', $values['source'])
->set('show_source', $values['show_source'])
->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. | |
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. | |
SettingsForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
SettingsForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
SettingsForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
SettingsForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
SettingsForm:: |
public | function |
Form validation handler. Overrides FormBase:: |
|
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. |