class GlobalredirectSettingsForm in Global Redirect 8
Defines a form to configure 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\globalredirect\Form\GlobalredirectSettingsForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of GlobalredirectSettingsForm
1 string reference to 'GlobalredirectSettingsForm'
File
- src/
Form/ GlobalredirectSettingsForm.php, line 17 - This is the GlobalRedirect admin include which provides an interface to global redirect to change some of the default settings Contains \Drupal\globalredirect\Form\GlobalredirectSettingsForm.
Namespace
Drupal\globalredirect\FormView source
class GlobalredirectSettingsForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
public function getFormID() {
return 'globalredirect_settings';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'globalredirect.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
// Get all settings
$config = $this
->config('globalredirect.settings');
$settings = $config
->get();
$form['settings'] = array(
'#tree' => TRUE,
);
$form['settings']['deslash'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Deslash'),
'#description' => $this
->t('If enabled, this option will remove the trailing slash from requests. This stops requests such as <code>example.com/node/1/</code> failing to match the corresponding alias and can cause duplicate content. On the other hand, if you require certain requests to have a trailing slash, this feature can cause problems so may need to be disabled.'),
'#default_value' => $settings['deslash'],
);
$form['settings']['nonclean_to_clean'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Non-clean to Clean'),
'#description' => $this
->t('If enabled, this option will redirect from non-clean to clean URL (if Clean URL\'s are enabled). This will stop, for example, node 1 existing on both <code>example.com/node/1</code> AND <code>example.com/index.php/node/1</code>.'),
'#default_value' => $settings['nonclean_to_clean'],
);
$form['settings']['access_check'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Check access to the redirected page'),
'#description' => $this
->t('This helps to stop redirection on protected pages and avoids giving away <em>secret</em> URL\'s. <strong>By default this feature is disabled to avoid any unexpected behavior</strong>'),
'#default_value' => $settings['access_check'],
);
$form['settings']['normalize_aliases'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Normalize aliases'),
'#description' => $this
->t('Will check if for the given path an alias exists or if the used alias is in correct case and will redirect to the appropriate alias form.'),
'#default_value' => $settings['normalize_aliases'],
);
$form['settings']['canonical'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Add Canonical Link'),
'#description' => $this
->t('If enabled, will add a <a href="!canonical">canonical link</a> to each page.', array(
'!canonical' => 'http://googlewebmastercentral.blogspot.com/2009/02/specify-your-canonical.html',
)),
'#default_value' => $settings['canonical'],
);
$form['settings']['content_location_header'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Set Content Location Header'),
'#description' => $this
->t('If enabled, will add a <a href="!canonical">Content-Location</a> header.', array(
'!canonical' => 'http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.14',
)),
'#default_value' => $settings['content_location_header'],
);
$form['settings']['term_path_handler'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Taxonomy Term Path Handler'),
'#description' => $this
->t('If enabled, any request to a taxonomy/term/[tid] page will check that the correct path is being used for the term\'s vocabulary.'),
'#default_value' => $settings['term_path_handler'],
);
$form['settings']['frontpage_redirect'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Frontpage Redirect Handler'),
'#description' => $this
->t('If enabled, any request to the frontpage path will redirect to the site root.<br />
Whatever you set as the path of the front page on the !link settings page will redirect to the site root (e.g. "node" or "node/1" and also its alias (e.g. in case you have set "node/1" as your home page but that page also has an alias "home")).', array(
'!link' => $this
->l($this
->t('Site Information'), Url::fromRoute('system.site_information_settings')),
)),
'#default_value' => $settings['frontpage_redirect'],
);
$form['settings']['ignore_admin_path'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Ignore Admin Path'),
'#description' => $this
->t('If enabled, any request to the admin section of the site will be ignored by Global Redirect.<br />
This is useful if you are experiencing problems with Global Redirect and want to protect the admin section of your website. NOTE: This may not be desirable if you are using path aliases for certain admin URLs.'),
'#default_value' => $settings['ignore_admin_path'],
);
$form['buttons']['reset'] = array(
'#type' => 'submit',
'#submit' => array(
'::submitResetDefaults',
),
'#value' => t('Reset to defaults'),
);
return parent::buildForm($form, $form_state);
}
/**
* Compares the submitted settings to the defaults and unsets any that are equal. This was we only store overrides.
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// Get config factory
$config = $this
->config('globalredirect.settings');
$form_values = $form_state
->getValue([
'settings',
]);
$config
->set('deslash', $form_values['deslash'])
->set('nonclean_to_clean', $form_values['nonclean_to_clean'])
->set('access_check', $form_values['access_check'])
->set('normalize_aliases', $form_values['normalize_aliases'])
->set('canonical', $form_values['canonical'])
->set('content_location_header', $form_values['content_location_header'])
->set('term_path_handler', $form_values['term_path_handler'])
->set('frontpage_redirect', $form_values['frontpage_redirect'])
->set('ignore_admin_path', $form_values['ignore_admin_path'])
->save();
parent::submitForm($form, $form_state);
}
/**
* Clears the caches.
*/
public function submitResetDefaults(array &$form, FormStateInterface $form_state) {
$config = $this
->config('globalredirect.settings');
// Get config factory
$settingsDefault = $this
->getDefaultSettings();
$config
->set('deslash', $settingsDefault['deslash'])
->set('nonclean_to_clean', $settingsDefault['nonclean_to_clean'])
->set('access_check', $settingsDefault['access_check'])
->set('normalize_aliases', $settingsDefault['normalize_aliases'])
->set('canonical', $settingsDefault['canonical'])
->set('content_location_header', $settingsDefault['content_location_header'])
->set('term_path_handler', $settingsDefault['term_path_handler'])
->set('frontpage_redirect', $settingsDefault['frontpage_redirect'])
->set('ignore_admin_path', $settingsDefault['ignore_admin_path'])
->save();
parent::submitForm($form, $form_state);
}
/**
* Returns an associative array of default settings
* @return array
*/
public function getDefaultSettings() {
$defaults = array(
'deslash' => 1,
'nonclean_to_clean' => 1,
'access_check' => 0,
'normalize_aliases' => 1,
'canonical' => 0,
'content_location_header' => 0,
'term_path_handler' => 1,
'frontpage_redirect' => 1,
'ignore_admin_path' => 1,
);
return $defaults;
}
}
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 |
FormInterface:: |
public | function | Returns a unique string identifying the form. | 236 |
GlobalredirectSettingsForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
GlobalredirectSettingsForm:: |
public | function | Returns an associative array of default settings | |
GlobalredirectSettingsForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
GlobalredirectSettingsForm:: |
public | function | ||
GlobalredirectSettingsForm:: |
public | function |
Compares the submitted settings to the defaults and unsets any that are equal. This was we only store overrides. Overrides ConfigFormBase:: |
|
GlobalredirectSettingsForm:: |
public | function | Clears the caches. | |
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. |