diff --git a/core/modules/system/lib/Drupal/system/Controller/ThemeController.php b/core/modules/system/lib/Drupal/system/Controller/ThemeController.php
index 852d2b6..353317f 100644
--- a/core/modules/system/lib/Drupal/system/Controller/ThemeController.php
+++ b/core/modules/system/lib/Drupal/system/Controller/ThemeController.php
@@ -7,45 +7,45 @@
 
 namespace Drupal\system\Controller;
 
-use Drupal\Core\Config\Config;
+use Drupal\Core\Controller\ControllerBase;
 use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
 use Symfony\Component\DependencyInjection\ContainerInterface;
-use Symfony\Component\HttpFoundation\RedirectResponse;
+use Drupal\Core\Access\CsrfTokenGenerator;
 use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
+use Symfony\Component\HttpFoundation\RedirectResponse;
 
 /**
  * Controller for theme handling.
  */
-class ThemeController implements ContainerInjectionInterface {
+class ThemeController extends ControllerBase implements ContainerInjectionInterface {
 
   /**
-   * The system.theme config object.
+   * Token generator service.
    *
-   * @var \Drupal\Core\Config\Config
+   * @var \Drupal\Core\Access\CsrfTokenGenerator
    */
-  protected $config;
-
-  /**
-   * Constructs a ThemeController object.
-   *
-   * @param \Drupal\Core\Config\Config $config
-   *   The config.
-   */
-  public function __construct(Config $config) {
-    $this->config = $config;
-  }
+  protected $tokenGenerator;
 
   /**
    * {@inheritdoc}
    */
   public static function create(ContainerInterface $container) {
     return new static(
-      $container->get('config.factory')->get('system.theme')
+      $container->get('csrf_token')
     );
   }
 
   /**
+   * Constructs a Theme Controller Object.
+   *
+   * @param \Drupal\Core\Access\CsrfTokenGenerator $token_generator
+   *   Token Generator Service.
+   */
+  public function __construct(CsrfTokenGenerator $token_generator) {
+    $this->tokenGenerator = $token_generator;
+  }
+  /**
    * Disables a theme.
    *
    * @param \Symfony\Component\HttpFoundation\Request $request
@@ -60,27 +60,25 @@ public static function create(ContainerInterface $container) {
    */
   public function disable(Request $request) {
     $theme = $request->get('theme');
-
-    if (isset($theme)) {
+    $token = $request->get('token');
+    $config = $this->config('system.theme');
+    if (isset($theme) && isset($token) && $this->tokenGenerator->validate($token, 'system-theme-operation-link')) {
       // Get current list of themes.
       $themes = list_themes();
 
       // Check if the specified theme is one recognized by the system.
       if (!empty($themes[$theme])) {
         // Do not disable the default or admin theme.
-        if ($theme === $this->config->get('default') || $theme === $this->config->get('admin')) {
-          drupal_set_message(t('%theme is the default theme and cannot be disabled.', array('%theme' => $themes[$theme]->info['name'])), 'error');
+        if ($theme === $config->get('default') || $theme === $config->get('admin')) {
+          drupal_set_message($this->t('%theme is the default theme and cannot be disabled.', array('%theme' => $themes[$theme]->info['name'])), 'error');
         }
         else {
           theme_disable(array($theme));
-          drupal_set_message(t('The %theme theme has been disabled.', array('%theme' => $themes[$theme]->info['name'])));
+          drupal_set_message($this->t('The %theme theme has been disabled.', array('%theme' => $themes[$theme]->info['name'])));
         }
       }
-      else {
-        drupal_set_message(t('The %theme theme was not found.', array('%theme' => $theme)), 'error');
-      }
 
-      return new RedirectResponse(url('admin/appearance', array('absolute' => TRUE)));
+      return new RedirectResponse($this->urlGenerator()->generateFromPath('admin/appearance', array('absolute' => TRUE)));
     }
 
     throw new AccessDeniedHttpException();
@@ -101,24 +99,89 @@ public function disable(Request $request) {
    */
   public function enable(Request $request) {
     $theme = $request->get('theme');
+    $token = $request->get('token');
+    $config = $this->config('system.theme');
 
-    if (isset($theme)) {
+    if (isset($theme) && isset($token) && $this->tokenGenerator->validate($token, 'system-theme-operation-link')) {
       // Get current list of themes.
       $themes = list_themes(TRUE);
 
       // Check if the specified theme is one recognized by the system.
       if (!empty($themes[$theme])) {
         theme_enable(array($theme));
-        drupal_set_message(t('The %theme theme has been enabled.', array('%theme' => $themes[$theme]->info['name'])));
+        drupal_set_message($this->t('The %theme theme has been enabled.', array('%theme' => $themes[$theme]->info['name'])));
       }
       else {
-        drupal_set_message(t('The %theme theme was not found.', array('%theme' => $theme)), 'error');
+        drupal_set_message($this->t('The %theme theme was not found.', array('%theme' => $theme)), 'error');
       }
 
-      return new RedirectResponse(url('admin/appearance', array('absolute' => TRUE)));
+      // @todo switch to $this->redirect when admin/appearance converted.
+      return new RedirectResponse($this->urlGenerator()->generateFromPath('admin/appearance', array('absolute' => TRUE)));
     }
 
     throw new AccessDeniedHttpException();
   }
 
+  /**
+   * Set the default theme.
+   *
+   * @param \Symfony\Component\HttpFoundation\Request $request
+   *   A request object containing a theme name and a valid token.
+   *
+   * @return \Symfony\Component\HttpFoundation\RedirectResponse
+   *   Redirects back to the appearance admin page.
+   *
+   * @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
+   *   Throws access denied when no theme or token is set in the request or when
+   *   the token is invalid.
+   */
+  public function defaultTheme(Request $request) {
+    $config = $this->config('system.theme');
+
+    $theme = $request->query->get('theme');
+    $token = $request->query->get('token');
+    if (isset($theme) && isset($token) && $this->tokenGenerator->validate($token, 'system-theme-operation-link')) {
+      // Get current list of themes.
+      $themes = list_themes();
+
+      // Check if the specified theme is one recognized by the system.
+      if (!empty($themes[$theme])) {
+        // Enable the theme if it is currently disabled.
+        if (empty($themes[$theme]->status)) {
+          theme_enable(array($theme));
+        }
+
+        // Set the default theme.
+        $config->set('default', $theme)->save();
+
+        // Rebuild the menu. This duplicates the menu_router_rebuild() in
+        // theme_enable(). However, modules must know the current default theme in
+        // order to use this information in hook_menu() or hook_menu_alter()
+        // implementations, and doing the variable_set() before the theme_enable()
+        // could result in a race condition where the theme is default but not
+        // enabled.
+        menu_router_rebuild();
+
+        // The status message depends on whether an admin theme is currently in use:
+        // a value of 0 means the admin theme is set to be the default theme.
+        $admin_theme = $config->get('admin');
+        if ($admin_theme != 0 && $admin_theme != $theme) {
+          drupal_set_message($this->t('Please note that the administration theme is still set to the %admin_theme theme; consequently, the theme on this page remains unchanged. All non-administrative sections of the site, however, will show the selected %selected_theme theme by default.', array(
+            '%admin_theme' => $themes[$admin_theme]->info['name'],
+            '%selected_theme' => $themes[$theme]->info['name'],
+          )));
+        }
+        else {
+          drupal_set_message($this->t('%theme is now the default theme.', array('%theme' => $themes[$theme]->info['name'])));
+        }
+      }
+      else {
+        drupal_set_message($this->t('The %theme theme was not found.', array('%theme' => $theme)), 'error');
+      }
+      // @todo switch to $this->redirect when admin/appearance converted.
+      return new RedirectResponse($this->urlGenerator()->generateFromPath('admin/appearance', array('absolute' => TRUE)));
+    }
+    throw new AccessDeniedHttpException();
+  }
+
 }
diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc
index 3af30c8..5ec6246 100644
--- a/core/modules/system/system.admin.inc
+++ b/core/modules/system/system.admin.inc
@@ -234,6 +234,9 @@ function system_theme_default() {
     return new RedirectResponse(url('admin/appearance', array('absolute' => TRUE)));
   }
   throw new AccessDeniedHttpException();
+=======
+  Drupal::config('system.theme')->set('admin', $form_state['values']['admin_theme'])->save();
+>>>>>>> Applied patch drupal8.system_theme_default.1987848-87
 }
 
 /**
@@ -414,6 +417,7 @@ function theme_admin_page($variables) {
 function theme_system_admin_index($variables) {
   $menu_items = $variables['menu_items'];
 
+  $stripe = 0;
   $container = array('left' => '', 'right' => '');
   $flip = array('left' => 'right', 'right' => 'left');
   $position = 'left';
@@ -618,12 +622,7 @@ function theme_system_modules_details($variables) {
     $rows[] = $row;
   }
 
-  $table = array(
-    '#theme' => 'table',
-    '#header' => $form['#header'],
-    '#rows' => $rows,
-  );
-  return drupal_render($table);
+  return theme('table', array('header' => $form['#header'], 'rows' => $rows));
 }
 
 /**
diff --git a/core/modules/system/system.routing.yml b/core/modules/system/system.routing.yml
index c1a7a37..fee99f1 100644
--- a/core/modules/system/system.routing.yml
+++ b/core/modules/system/system.routing.yml
@@ -357,6 +357,14 @@ system.modules_uninstall_confirm:
   requirements:
     _permission: 'administer modules'
 
+system.theme_default:
+  path: '/admin/appearance/default'
+  defaults:
+    _controller: '\Drupal\system\Controller\ThemeController::defaultTheme'
+    _title: 'Set default theme'
+  requirements:
+    _permission: 'administer themes'
+
 system.timezone:
   path: '/system/timezone/{abbreviation}/{offset}/{is_daylight_saving_time}'
   defaults:
