function public static function Bootstrap::getTheme

8.x-3.x Bootstrap.php public static Bootstrap::getTheme($name = NULL, ThemeHandlerInterface $theme_handler = NULL)

Retrieves a theme instance of \Drupal\bootstrap.


string $name: The machine name of a theme. If omitted, the active theme will be used.

\Drupal\Core\Extension\ThemeHandlerInterface $theme_handler: The theme handler object.

Return value

\Drupal\bootstrap\Theme A theme object.


The primary class for the Drupal Bootstrap base theme.



Source src/Bootstrap.php (line 669)

public static function getTheme($name = NULL, ThemeHandlerInterface $theme_handler = NULL) {
  // Immediately return if theme passed is already instantiated.
  if ($name instanceof Theme) {
    return $name;

  static $themes = [];

  // Retrieve the active theme.
  // Do not statically cache this as the active theme may change.
  if (!isset($name)) {
    $name = \Drupal::theme()->getActiveTheme()->getName();

  if (!isset($theme_handler)) {
    $theme_handler = self::getThemeHandler();

  if (!isset($themes[$name])) {
    $themes[$name] = new Theme($theme_handler->getTheme($name), $theme_handler);

  return $themes[$name];