class AddToHomescreenForm in Add to homescreen 8
Configure Add to Homescreen.
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\addtohomescreen\Form\AddToHomescreenForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of AddToHomescreenForm
1 string reference to 'AddToHomescreenForm'
File
- src/
Form/ AddToHomescreenForm.php, line 11
Namespace
Drupal\addtohomescreen\FormView source
class AddToHomescreenForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'addtohomescreen_settings_form';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'addtohomescreen.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
$config = $this
->config('addtohomescreen.settings');
$form['library'] = [
'#type' => 'details',
'#title' => $this
->t('Configuration'),
'#description' => $this
->t('For more information about these options, visit <a href="@addtohomescreen_url">Add to homescreen on Github</a>.', [
'@addtohomescreen_url' => 'https://github.com/cubiq/add-to-homescreen',
]),
'#open' => TRUE,
];
$form['library']['debug'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Debug mode'),
'#description' => $this
->t('Some of the preliminary checks are skipped and the message is shown on desktop browsers and unsupported devices as well.'),
'#default_value' => $config
->get('debug'),
];
$form['library']['modal'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Modal'),
'#description' => $this
->t('Prevents further actions on the website until the message is closed.'),
'#default_value' => $config
->get('modal'),
];
$form['library']['mandatory'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Mandatory'),
'#description' => $this
->t('The website is not accessible until the user adds the website to the homescreen.'),
'#default_value' => $config
->get('mandatory'),
];
$form['library']['skipfirstvisit'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Skip first visit'),
'#description' => $this
->t('Prevent the message from appearing the first time the user visits your website. It is highly recommended to enable this option!'),
'#default_value' => $config
->get('skipfirstvisit'),
];
$form['library']['autostart'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Autostart'),
'#description' => $this
->t('The message is not shown automatically and you have to trigger it programmatically.'),
'#default_value' => $config
->get('autostart'),
];
$form['library']['icon'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Icon'),
'#description' => $this
->t('Display the touch icon in the pop up message.'),
'#default_value' => $config
->get('icon'),
];
$form['library']['startdelay'] = [
'#type' => 'textfield',
'#title' => $this
->t('Start delay'),
'#description' => $this
->t('Seconds to wait from page load before showing the message.'),
'#default_value' => $config
->get('startdelay'),
'#size' => 10,
];
$form['library']['lifespan'] = [
'#type' => 'textfield',
'#title' => $this
->t('Lifespan'),
'#description' => $this
->t('Seconds to wait before automatically closing the message. Set to 0 to disable automatic removal.'),
'#default_value' => $config
->get('lifespan'),
'#size' => 10,
];
$form['library']['displaypace'] = [
'#type' => 'textfield',
'#title' => $this
->t('Display pace'),
'#description' => $this
->t('Minutes before the message is shown again. By default it is set to 1440, meaning the message is shown once per day.'),
'#default_value' => $config
->get('displaypace'),
'#size' => 10,
];
$form['library']['maxdisplaycount'] = [
'#type' => 'textfield',
'#title' => $this
->t('Maximum display count'),
'#description' => $this
->t('Absolute maximum number of times the call out will be shown. Set to 0 for no maximum.'),
'#default_value' => $config
->get('maxdisplaycount'),
'#size' => 10,
];
$form['library']['use_custom_message'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Use a custom message'),
'#description' => $this
->t('Add to homescreen comes with a localized and device specific message. You can override this message with your own.'),
'#default_value' => $config
->get('use_custom_message'),
];
$form['library']['message'] = [
'#title' => $this
->t('Message'),
'#type' => 'textarea',
'#default_value' => $config
->get('message', $this
->t('To add this web app to the home screen: tap %icon and then <strong>Add to homescreen</strong>.')),
'#description' => $this
->t('Available replacements: %icon'),
'#states' => [
'disabled' => [
':input[name="use_custom_message"]' => [
'checked' => FALSE,
],
],
],
];
$form['compression_settings'] = [
'#type' => 'details',
'#title' => $this
->t('Library compression settings'),
'#collapsible' => TRUE,
'#open' => FALSE,
];
$form['compression_settings']['compression_type'] = [
'#type' => 'radios',
'#title' => $this
->t('Choose compression level'),
'#options' => [
'minified' => $this
->t('Production (Minified)'),
'source' => $this
->t('Development (Uncompressed Code)'),
],
'#default_value' => $config
->get('compression_type', 'minified'),
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this
->config('addtohomescreen.settings')
->set('debug', $form_state
->getValue('debug'))
->set('modal', $form_state
->getValue('modal'))
->set('mandatory', $form_state
->getValue('mandatory'))
->set('skipfirstvisit', $form_state
->getValue('skipfirstvisit'))
->set('autostart', $form_state
->getValue('autostart'))
->set('icon', $form_state
->getValue('icon'))
->set('startdelay', $form_state
->getValue('startdelay'))
->set('lifespan', $form_state
->getValue('lifespan'))
->set('displaypace', $form_state
->getValue('displaypace'))
->set('maxdisplaycount', $form_state
->getValue('maxdisplaycount'))
->set('use_custom_message', $form_state
->getValue('use_custom_message'))
->set('message', $form_state
->getValue('message'))
->set('compression_type', $form_state
->getValue('compression_type'))
->save();
parent::submitForm($form, $form_state);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AddToHomescreenForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
AddToHomescreenForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
AddToHomescreenForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
AddToHomescreenForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
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. | |
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. |