',
+ )),
);
- return system_settings_form($form);
+ $form['#submit'][] = 'r4032login_form_system_site_information_settings_form_submit';
+}
+
+/**
+ * Form submission handler for system_site_information_settings().
+ *
+ * @see r4032login_form_system_site_information_settings_alter()
+ */
+function r4032login_form_system_site_information_settings_form_submit($form, &$form_state) {
+ \Drupal::config('r4032login.settings')
+ ->set('display_denied_message', $form_state['values']['r4032login_display_denied_message'])
+ ->set('access_denied_message', $form_state['values']['r4032login_access_denied_message'])
+ ->set('redirect_authenticated_users_to', $form_state['values']['r4032login_redirect_authenticated_users_to'])
+ ->set('user_login_path', $form_state['values']['r4032login_user_login_path'])
+ ->set('default_redirect_code', $form_state['values']['r4032login_default_redirect_code'])
+ ->set('match_noredirect_pages', $form_state['values']['r4032login_match_noredirect_pages'])
+ ->save();
}
/**
@@ -99,73 +113,3 @@ function r4032login_theme() {
),
);
}
-
-/**
- * MENU_CALLBACK for /r4032login
- *
- * Redirect anonymous users from 403 Access Denied pages to the /user/login page
- * with a message explaining that they must log in to view the requested page
- * and a query string parameter appended to the url to return after login.
- */
-function r4032login_redirect() {
- global $user, $language;
- if (user_is_anonymous()) {
- // Show the access denied message.
- if (variable_get('r4032login_display_denied_message', TRUE) && empty($_POST)) {
- $message = variable_get('r4032login_access_denied_message', t('Access denied. You must log in to view this page.'));
- drupal_set_message($message, 'error');
- }
- $page_match = FALSE;
- $pages = variable_get('r4032login_match_noredirect_pages', '');
- if ($pages) {
- // When on an access denied page, Drupal stores the original path in
- // $_GET['destination'] in drupal_deliver_html_page().
- // Convert the Drupal path to lowercase.
- $path = drupal_strtolower(drupal_get_path_alias($_GET['destination']));
- // Compare the lowercase internal and lowercase path alias (if any).
- $page_match = drupal_match_path($path, $pages);
- if ($path != $_GET['destination']) {
- $page_match = $page_match || drupal_match_path($_GET['destination'], $pages);
- }
- }
- if ($page_match) {
- // Display the default login page.
- return drupal_get_form('user_login');
- }
- // Handle redirection to the login form.
- // using drupal_goto() with destination set causes a recursive redirect loop
- $login_path = variable_get('r4032login_user_login_path', 'user/login');
- $code = variable_get('r4032login_default_redirect_code', 302);
- // The code in drupal_get_destination() doesn't preserve any query string
- // on 403 pages, so reproduce the part we want here.
- $path = $_GET['destination'];
- $query = drupal_http_build_query(drupal_get_query_parameters(NULL, array('q', 'destination')));
- if ($query != '') {
- $path .= '?' . $query;
- }
- $destination = array('destination' => $path);
- header('Location: ' . url($login_path, array('query' => $destination, 'absolute' => TRUE)), TRUE, $code);
- drupal_exit();
- }
- else {
- // Check to see if we are to redirect the user.
- $redirect = variable_get('r4032login_redirect_authenticated_users_to', '');
- if (empty($redirect)) {
- // Display the default access denied page.
- return theme('r4032login_denied');
- }
- else {
- // Custom access denied page for logged in users.
- header('Location: ' . url($redirect, array('absolute' => TRUE)));
- drupal_exit();
- }
- }
-}
-
-/**
- * Display themed Access denied page.
- */
-function theme_r4032login_denied() {
- drupal_set_title(t('Access denied'));
- return '' . t('You are not authorized to access this page.') . '
';
-}
diff --git a/r4032login.services.yml b/r4032login.services.yml
new file mode 100644
index 0000000..95ffb1d
--- /dev/null
+++ b/r4032login.services.yml
@@ -0,0 +1,7 @@
+services:
+ r4032login.subscriber:
+ class: Drupal\r4032login\EventSubscriber\R4032LoginSubscriber
+ arguments: ['@state']
+ tags:
+ - { name: event_subscriber }
+ - { name: needs_destruction }
diff --git a/r4032login.variable.inc b/r4032login.variable.inc
deleted file mode 100644
index 65159de..0000000
--- a/r4032login.variable.inc
+++ /dev/null
@@ -1,75 +0,0 @@
- 'boolean',
- 'title' => t('Display access denied message on login page', array(), $options),
- 'default' => 1,
- 'description' => t('Displays an access denied message on the user login page.', array(), $options),
- 'group' => 'r4032login',
- );
- $variables['r4032login_access_denied_message'] = array(
- 'type' => 'string',
- 'title' => t("User login 'access denied' message", array(), $options),
- 'default' => t('Access denied. You must log in to view this page.', array(), $options),
- 'description' => t('The message text displayed to users who are denied access to the page.', array(), $options),
- 'group' => 'r4032login',
- );
- $variables['r4032login_redirect_authenticated_users_to'] = array(
- 'type' => 'drupal_path',
- 'title' => t('Redirect authenticated users to', array(), $options),
- 'default' => '',
- 'description' => t('If an authenticated user tries to access a page they can not, redirect them to the given page. Use <front> for the front page, leave blank for a default access denied page.', array(), $options),
- 'group' => 'r4032login',
- );
- $variables['r4032login_user_login_path'] = array(
- 'type' => 'drupal_path',
- 'title' => t('Path to user login form', array(), $options),
- 'default' => 'user/login',
- 'description' => t('The path to the user login form. Omit the beginning slash, ie: user/login', array(), $options),
- 'group' => 'r4032login',
- );
- $variables['r4032login_default_redirect_code'] = array(
- 'type' => 'select',
- 'title' => t("HTTP default redirect code"),
- 'description' => t('The redirect code to send by default. 301 responses may be cached by browsers and proxies.'),
- 'default_value' => 302,
- 'group' => 'r4032login',
- );
- $variables['r4032login_match_redirect_code'] = array(
- 'type' => 'select',
- 'title' => t("HTTP redirect code to use for matching pages"),
- 'description' => t('The redirect code to send for paths that match. 301 responses may be cached by browsers and proxies.'),
- 'default' => 301,
- );
- $variables['r4032login_match_redirect_pages'] = array(
- 'type' => 'drupal_path',
- 'title' => t('Specify matching pages by using their paths.'),
- 'default' => '',
- 'description' => t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '')),
- 'group' => 'r4032login',
- );
- return $variables;
-}
-
-/**
- * Implements hook_variable_group_info().
- */
-function r4032login_variable_group_info() {
- $groups['r4032login'] = array(
- 'title' => t('Redirect 403 to User Login'),
- 'description' => t('Redirect anonymous users from 403 Access Denied pages to the user/login page.'),
- 'access' => 'administer site configuration',
- 'path' => array('admin/config/system/site-information'),
- );
-
- return $groups;
-}