Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / redirect / src / Form / RedirectSettingsForm.php
1 <?php
2
3 namespace Drupal\redirect\Form;
4
5 use Drupal\Core\Form\ConfigFormBase;
6 use Drupal\Core\Form\FormStateInterface;
7
8 class RedirectSettingsForm extends ConfigFormBase {
9
10   /**
11    * {@inheritdoc}
12    */
13   public function getFormId() {
14     return 'redirect_settings_form';
15   }
16   /**
17    * {@inheritdoc}
18    */
19   protected function getEditableConfigNames() {
20     return ['redirect.settings'];
21   }
22
23   /**
24    * {@inheritdoc}
25    */
26   public function buildForm(array $form, FormStateInterface $form_state) {
27     $config = $this->config('redirect.settings');
28     $form['redirect_auto_redirect'] = array(
29       '#type' => 'checkbox',
30       '#title' => $this->t('Automatically create redirects when URL aliases are changed.'),
31       '#default_value' => $config->get('auto_redirect'),
32       '#disabled' => !\Drupal::moduleHandler()->moduleExists('path'),
33     );
34     $form['redirect_passthrough_querystring'] = array(
35       '#type' => 'checkbox',
36       '#title' => $this->t('Retain query string through redirect.'),
37       '#default_value' => $config->get('passthrough_querystring'),
38       '#description' => $this->t('For example, given a redirect from %source to %redirect, if a user visits %sourcequery they would be redirected to %redirectquery. The query strings in the redirection will always take precedence over the current query string.', array('%source' => 'source-path', '%redirect' => 'node?a=apples', '%sourcequery' => 'source-path?a=alligators&b=bananas', '%redirectquery' => 'node?a=apples&b=bananas')),
39     );
40     $form['redirect_warning'] = array(
41       '#type' => 'checkbox',
42       '#title' => $this->t('Display a warning message to users when they are redirected.'),
43       '#default_value' => $config->get('warning'),
44       '#access' => FALSE,
45     );
46     $form['redirect_default_status_code'] = array(
47       '#type' => 'select',
48       '#title' => $this->t('Default redirect status'),
49       '#description' => $this->t('You can find more information about HTTP redirect status codes at <a href="@status-codes">@status-codes</a>.', array('@status-codes' => 'http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#3xx_Redirection')),
50       '#options' => redirect_status_code_options(),
51       '#default_value' => $config->get('default_status_code'),
52     );
53     $form['globals'] = array(
54       '#type' => 'fieldset',
55       '#title' => $this->t('Global redirects'),
56       '#description' => $this->t('(formerly Global Redirect features)'),
57     );
58     $form['globals']['redirect_route_normalizer_enabled'] = array(
59       '#type' => 'checkbox',
60       '#title' => $this->t('Enforce clean and canonical URLs.'),
61       '#description' => $this->t('Enabling this will automatically redirect to the canonical URL of any page. That includes redirecting to an alias if existing, removing trailing slashes, ensure the language prefix is set and similar clean-up.'),
62       '#default_value' => $config->get('route_normalizer_enabled'),
63     );
64     $form['globals']['redirect_ignore_admin_path'] = array(
65       '#type' => 'checkbox',
66       '#title' => $this->t('Ignore redirections on admin paths.'),
67       '#default_value' => $config->get('ignore_admin_path'),
68     );
69     $form['globals']['redirect_access_check'] = array(
70       '#type' => 'checkbox',
71       '#title' => $this->t('Check access to the redirected page'),
72       '#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>'),
73       '#default_value' => $config->get('access_check'),
74     );
75
76     return parent::buildForm($form, $form_state);
77   }
78
79   /**
80    * {@inheritdoc}
81    */
82   public function submitForm(array &$form, FormStateInterface $form_state) {
83     $config = $this->config('redirect.settings');
84     foreach ($form_state->getValues() as $key => $value) {
85       if (strpos($key, 'redirect_') !== FALSE) {
86         $config->set(str_replace('redirect_', '', $key), $value);
87       }
88     }
89     $config->save();
90     drupal_set_message($this->t('Configuration was saved.'));
91   }
92
93 }