public function ThemeController::enable

Enables a theme.

Parameters

\Symfony\Component\HttpFoundation\Request $request: A request object containing a theme name and a valid token.

Return value

\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.

1 string reference to 'ThemeController::enable'
system.routing.yml in drupal/core/modules/system/system.routing.yml
drupal/core/modules/system/system.routing.yml

File

drupal/core/modules/system/lib/Drupal/system/Controller/ThemeController.php, line 103
Contains \Drupal\system\Controller\ThemeController.

Class

ThemeController
Controller for theme handling.

Namespace

Drupal\system\Controller

Code

public function enable(Request $request) {
  $theme = $request
    ->get('theme');
  $token = $request
    ->get('token');
  if (isset($theme) && isset($token) && drupal_valid_token($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])) {
      theme_enable(array(
        $theme,
      ));
      drupal_set_message(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');
    }
    return new RedirectResponse(url('admin/appearance', array(
      'absolute' => TRUE,
    )));
  }
  throw new AccessDeniedHttpException();
}