class SecurepagesSettingsForm in Secure Pages 8
Defines a form that configures forms module 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\securepages\Form\SecurepagesSettingsForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of SecurepagesSettingsForm
1 string reference to 'SecurepagesSettingsForm'
File
- src/
Form/ SecurepagesSettingsForm.php, line 18 - Contains \Drupal\securepages\Form\SecurepagesSettingsForm.
Namespace
Drupal\securepages\FormView source
class SecurepagesSettingsForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'securepages_admin_settings';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'securepages.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL) {
$config = $this
->config('securepages.settings');
$secure = 0;
if ($config
->get('secure')) {
$secure = 1;
}
$form['enable'] = array(
'#type' => 'checkbox',
'#title' => t('Enable Secure Pages'),
'#default_value' => $config
->get('enable'),
'#disabled' => !Securepages::isHTTPSSupported(),
'#description' => $this
->t('To start using secure pages this setting must be enabled. This setting will only be possible to change when the web server has been configured for HTTPS. You may need to set the secure base URL below in case of a custom port. <a href=":url">You can manually visit the site in HTTPS too</a>.', array(
':url' => Securepages::getUrl('<front>')
->toString(),
)),
);
$form['switch'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Switch back to HTTP pages when there are no matches'),
'#default_value' => $config
->get('switch'),
);
$form['basepath'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Non-secure base URL'),
'#default_value' => $config
->get('basepath'),
'#size' => 100,
);
$form['basepath_ssl'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Secure base URL'),
'#default_value' => $config
->get('basepath_ssl'),
'#size' => 100,
);
$active_options = [
0 => $this
->t('Pages not matching the patterns should be secure'),
1 => $this
->t('Pages matching the patterns should be secure'),
];
$form['secure'] = array(
'#type' => 'radios',
'#title' => $this
->t('Which pages will be secure'),
'#default_value' => $secure,
'#options' => $active_options,
);
$form['pages'] = array(
'#title' => $this
->t('Pages'),
'#type' => 'textarea',
'#default_value' => implode("\n", $config
->get('pages')),
'#cols' => 40,
'#rows' => 5,
'#description' => $this
->t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are '<em>blog</em>' for the main blog page and '<em>blog/*</em>' for every personal blog. '<em><front></em>' is the front page."),
);
$form['ignore'] = array(
'#type' => 'textarea',
'#title' => $this
->t('Ignore pages'),
'#default_value' => implode("\n", $config
->get('ignore')),
'#cols' => 40,
'#rows' => 5,
'#description' => $this
->t("The pages listed here will be ignored and be either returned in HTTP or HTTPS. Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are '<em>blog</em>' for the blog page and '<em>blog/*</em>' for every personal blog. '<em><front></em>' is the front page."),
);
$form['roles'] = array(
'#type' => 'checkboxes',
'#title' => $this
->t('User roles'),
'#description' => $this
->t('Users with the chosen role(s) are always redirected to HTTPS, regardless of path rules.'),
'#options' => user_role_names(),
'#default_value' => $config
->get('roles'),
);
$form['forms'] = array(
'#type' => 'textarea',
'#title' => $this
->t('Secure forms'),
'#default_value' => implode("\n", $config
->get('forms')),
'#cols' => 40,
'#rows' => 5,
'#description' => $this
->t('List of form ids which will have the HTTPS flag set to TRUE.'),
);
$form['debug'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Enable debugging'),
'#default_value' => $config
->get('debug'),
'#description' => $this
->t('Turn on debugging to allow easier testing of settings.'),
);
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this
->config('securepages.settings')
->set('enable', $form_state
->getValue('enable'))
->set('switch', $form_state
->getValue('switch'))
->set('basepath', $form_state
->getValue('basepath'))
->set('basepath_ssl', $form_state
->getValue('basepath_ssl'))
->set('secure', $form_state
->getValue('secure'))
->set('pages', $this::explodeValues($form_state
->getValue('pages')))
->set('ignore', $this::explodeValues($form_state
->getValue('ignore')))
->set('roles', array_filter($form_state
->getValue('roles')))
->set('forms', $this::explodeValues($form_state
->getValue('forms')))
->set('debug', $form_state
->getValue('debug'))
->save();
parent::submitForm($form, $form_state);
}
/**
* Explode $values and returned a clean array with options.
*
* @param string $values
* Values as entered in the form, separated by newlines.
*
* @return array
* Array formatted trimmed values with empty items removed.
*/
private static function explodeValues($values) {
// Convert string to an array, trim whitespace on each item, remove
// empty items and reindex array for clean export.
return array_values(array_filter(array_map('trim', explode("\n", $values))));
}
}
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. | |
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. | |
SecurepagesSettingsForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
SecurepagesSettingsForm:: |
private static | function | Explode $values and returned a clean array with options. | |
SecurepagesSettingsForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
SecurepagesSettingsForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
SecurepagesSettingsForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
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. |