diff --git a/core/lib/Drupal/Core/EventSubscriber/RouteProcessorSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/RouteProcessorSubscriber.php
index 0061530..f965360 100644
--- a/core/lib/Drupal/Core/EventSubscriber/RouteProcessorSubscriber.php
+++ b/core/lib/Drupal/Core/EventSubscriber/RouteProcessorSubscriber.php
@@ -38,8 +38,18 @@ public function __construct(ContentNegotiation $negotiation) {
public function onRequestSetController(GetResponseEvent $event) {
$request = $event->getRequest();
+ // @todo This should all get converted into one or more RouteEnhancers.
if (!$request->attributes->has('_controller') && $this->negotiation->getContentType($request) === 'html') {
- $request->attributes->set('_controller', '\Drupal\Core\HtmlPageController::content');
+ if ($request->attributes->has('_form')) {
+ $request->attributes->set('_controller', '\Drupal\Core\HtmlFormController::content');
+ }
+ elseif ($request->attributes->has('_content')) {
+ $request->attributes->set('_controller', '\Drupal\Core\HtmlPageController::content');
+ }
+ else {
+ throw new \InvalidArgumentException('No valid subcontroller key was found');
+ }
+
}
}
diff --git a/core/lib/Drupal/Core/HtmlFormController.php b/core/lib/Drupal/Core/HtmlFormController.php
new file mode 100644
index 0000000..5cd0712
--- /dev/null
+++ b/core/lib/Drupal/Core/HtmlFormController.php
@@ -0,0 +1,71 @@
+container = $container;
+ }
+
+ /**
+ * Controller method for generic HTML form pages.
+ *
+ * @param Request $request
+ * The request object.
+ * @param callable $_form
+ * The name of the form class for this request.
+ *
+ * @return \Symfony\Component\HttpFoundation\Response
+ * A response object.
+ */
+ public function content(Request $request, $_form) {
+ $form_state = array();
+
+ $args = $request->attributes->get('_form_arguments');
+
+ $form_state['build_info']['args'] = $args ?: array();
+
+ // @todo Add the ability for forms to have a factory method just like
+ // controllers. See http://drupal.org/node/1915774#comment-7140912.
+ // @todo We could probably make it possible to wire up a form as a service,
+ // too, but that may not be a common use case.
+ $form = new $_form;
+
+ $form_id = _drupal_form_id($form, $form_state);
+ $form_result = drupal_build_form($form_id, $form_state);
+
+ $response = new Response(drupal_render_page($form_result));
+
+ return $response;
+ }
+}
diff --git a/core/modules/system/lib/Drupal/system/Form/MaintenanceModeForm.php b/core/modules/system/lib/Drupal/system/Form/MaintenanceModeForm.php
new file mode 100644
index 0000000..ba4d1de
--- /dev/null
+++ b/core/modules/system/lib/Drupal/system/Form/MaintenanceModeForm.php
@@ -0,0 +1,80 @@
+ 'checkbox',
+ '#title' => t('Put site into maintenance mode'),
+ '#default_value' => $config->get('enabled'),
+ '#description' => t('Visitors will only see the maintenance mode message. Only users with the "Access site in maintenance mode" permission will be able to access the site. Authorized users can log in directly via the user login page.', array('@permissions-url' => url('admin/config/people/permissions'), '@user-login' => url('user'))),
+ );
+ $form['maintenance_mode_message'] = array(
+ '#type' => 'textarea',
+ '#title' => t('Message to display when in maintenance mode'),
+ '#default_value' => $config->get('message'),
+ );
+
+ return system_config_form($form, $form_state);
+ }
+
+ /**
+ * Form validation handler.
+ *
+ * @param array $form
+ * An associative array containing the structure of the form.
+ * @param array $form_state
+ * An associative array containing the current state of the form.
+ */
+ public function validateForm(array &$form, array &$form_state) {}
+
+ /**
+ * Form submission handler.
+ *
+ * @param array $form
+ * An associative array containing the structure of the form.
+ * @param array $form_state
+ * An associative array containing the current state of the form.
+ */
+ public function submitForm(array &$form, array &$form_state) {
+ config_context_enter('config.context.free');
+ config('system.maintenance')
+ ->set('enabled', $form_state['values']['maintenance_mode'])
+ ->set('message', $form_state['values']['maintenance_mode_message'])
+ ->save();
+ }
+}
diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc
index b367033..d7893b4 100644
--- a/core/modules/system/system.admin.inc
+++ b/core/modules/system/system.admin.inc
@@ -2021,43 +2021,6 @@ function system_regional_settings_submit($form, &$form_state) {
}
/**
- * Form builder; Configure the site's maintenance status.
- *
- * @ingroup forms
- * @see system_site_maintenance_mode_submit()
- */
-function system_site_maintenance_mode($form, &$form_state) {
- config_context_enter('config.context.free');
- $config = config('system.maintenance');
- $form['maintenance_mode'] = array(
- '#type' => 'checkbox',
- '#title' => t('Put site into maintenance mode'),
- '#default_value' => $config->get('enabled'),
- '#description' => t('Visitors will only see the maintenance mode message. Only users with the "Access site in maintenance mode" permission will be able to access the site. Authorized users can log in directly via the user login page.', array('@permissions-url' => url('admin/config/people/permissions'), '@user-login' => url('user'))),
- );
- $form['maintenance_mode_message'] = array(
- '#type' => 'textarea',
- '#title' => t('Message to display when in maintenance mode'),
- '#default_value' => $config->get('message'),
- );
-
- return system_config_form($form, $form_state);
-}
-
-/**
- * Form submission handler for system_site_maintenance_mode().
- *
- * @ingroup forms
- */
-function system_site_maintenance_mode_submit($form, &$form_state) {
- config_context_enter('config.context.free');
- config('system.maintenance')
- ->set('enabled', $form_state['values']['maintenance_mode'])
- ->set('message', $form_state['values']['maintenance_mode_message'])
- ->save();
-}
-
-/**
* Menu callback: displays the site status report. Can also be used as a pure check.
*
* @param $check
diff --git a/core/modules/system/system.module b/core/modules/system/system.module
index 3f01968..479a5a4 100644
--- a/core/modules/system/system.module
+++ b/core/modules/system/system.module
@@ -848,9 +848,7 @@ function system_menu() {
$items['admin/config/development/maintenance'] = array(
'title' => 'Maintenance mode',
'description' => 'Take the site offline for maintenance or bring it back online.',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('system_site_maintenance_mode'),
- 'access arguments' => array('administer site configuration'),
+ 'page callback' => 'NOT_USED',
'file' => 'system.admin.inc',
'weight' => -10,
);
diff --git a/core/modules/system/system.routing.yml b/core/modules/system/system.routing.yml
index 085895e..1bc6cf2 100644
--- a/core/modules/system/system.routing.yml
+++ b/core/modules/system/system.routing.yml
@@ -4,3 +4,10 @@ system.cron:
_controller: '\Drupal\system\CronController::run'
requirements:
_access_system_cron: 'TRUE'
+
+system.maintenance:
+ pattern: '/admin/config/development/maintenance'
+ defaults:
+ _form: '\Drupal\system\Form\MaintenanceModeForm'
+ requirements:
+ _permission: 'administer site configuration'