function ThemeController::install

Same name and namespace in other branches
  1. 11.x core/modules/system/src/Controller/ThemeController.php \Drupal\system\Controller\ThemeController::install()
  2. 10 core/modules/system/src/Controller/ThemeController.php \Drupal\system\Controller\ThemeController::install()
  3. 9 core/modules/system/src/Controller/ThemeController.php \Drupal\system\Controller\ThemeController::install()
  4. 8.9.x core/modules/system/src/Controller/ThemeController.php \Drupal\system\Controller\ThemeController::install()

Installs a theme.

Parameters

string $theme: The theme name.

Return value

\Symfony\Component\HttpFoundation\RedirectResponse|array Redirects back to the appearance admin page or the confirmation form if an experimental theme will be installed.

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

File

core/modules/system/src/Controller/ThemeController.php, line 104

Class

ThemeController
Controller for theme handling.

Namespace

Drupal\system\Controller

Code

public function install(#[MapQueryParameter] string $theme) {
  // Display confirmation form in case of experimental theme.
  if ($this->willInstallExperimentalTheme($theme)) {
    return $this->formBuilder()
      ->getForm(ThemeExperimentalConfirmForm::class, $theme);
  }
  try {
    if ($this->themeInstaller
      ->install([
      $theme,
    ])) {
      $themes = $this->themeHandler
        ->listInfo();
      $this->messenger()
        ->addStatus($this->t('The %theme theme has been installed.', [
        '%theme' => $themes[$theme]->info['name'],
      ]));
    }
    else {
      $this->messenger()
        ->addError($this->t('The %theme theme was not found.', [
        '%theme' => $theme,
      ]));
    }
  } catch (PreExistingConfigException $e) {
    $config_objects = $e->flattenConfigObjects($e->getConfigObjects());
    $this->messenger()
      ->addError($this->formatPlural(count($config_objects), 'Unable to install @extension, %config_names already exists in active configuration.', 'Unable to install @extension, %config_names already exist in active configuration.', [
      '%config_names' => implode(', ', $config_objects),
      '@extension' => $theme,
    ]));
  } catch (UnmetDependenciesException $e) {
    $this->messenger()
      ->addError($e->getTranslatedMessage($this->getStringTranslation(), $theme));
  } catch (MissingDependencyException) {
    $this->messenger()
      ->addError($this->t('Unable to install @theme due to missing module dependencies.', [
      '@theme' => $theme,
    ]));
  }
  return $this->redirect('system.themes_page');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.