Drupal 8  8.0.2
ThemeHandler Class Reference
Inheritance diagram for ThemeHandler:

Public Member Functions

 __construct ($root, ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, StateInterface $state, InfoParserInterface $info_parser, ExtensionDiscovery $extension_discovery=NULL)
 
 getDefault ()
 
 setDefault ($name)
 
 install (array $theme_list, $install_dependencies=TRUE)
 
 uninstall (array $theme_list)
 
 listInfo ()
 
 addTheme (Extension $theme)
 
 refreshInfo ()
 
 reset ()
 
 rebuildThemeData ()
 
 getBaseThemes (array $themes, $theme)
 
 getName ($theme)
 
 getThemeDirectories ()
 
 themeExists ($theme)
 
 getTheme ($name)
 
 hasUi ($name)
 

Protected Member Functions

 doGetBaseThemes (array $themes, $theme, $used_themes=array())
 
 getExtensionDiscovery ()
 
 systemListReset ()
 
 systemThemeList ()
 

Protected Attributes

 $defaultFeatures
 
 $list
 
 $configFactory
 
 $moduleHandler
 
 $state
 
 $configInstaller
 
 $infoParser
 
 $logger
 
 $routeBuilder
 
 $extensionDiscovery
 
 $cssCollectionOptimizer
 
 $configManager
 
 $root
 

Detailed Description

Default theme handler using the config system to store installation statuses.

Constructor & Destructor Documentation

__construct (   $root,
ConfigFactoryInterface  $config_factory,
ModuleHandlerInterface  $module_handler,
StateInterface  $state,
InfoParserInterface  $info_parser,
ExtensionDiscovery  $extension_discovery = NULL 
)

Constructs a new ThemeHandler.

Parameters
string$rootThe app root.
\Drupal\Core\Config\ConfigFactoryInterface$config_factoryThe config factory to get the installed themes.
\Drupal\Core\Extension\ModuleHandlerInterface$module_handlerThe module handler to fire themes_installed/themes_uninstalled hooks.
\Drupal\Core\State\StateInterface$stateThe state store.
\Drupal\Core\Extension\InfoParserInterface$info_parserThe info parser to parse the theme.info.yml files.
\Drupal\Core\Extension\ExtensionDiscovery$extension_discovery(optional) A extension discovery instance (for unit tests).

References Drupal\configFactory(), Drupal\moduleHandler(), Drupal\root(), and Drupal\state().

Here is the call graph for this function:

Member Function Documentation

addTheme ( Extension  $theme)

{Adds a theme extension to the internal listing.

Parameters
\Drupal\Core\Extension\Extension$themeThe theme extension.
}

Implements ThemeHandlerInterface.

References Extension\getName().

Referenced by ThemeHandler\listInfo(), and ThemeHandler\refreshInfo().

Here is the call graph for this function:

Here is the caller graph for this function:

doGetBaseThemes ( array  $themes,
  $theme,
  $used_themes = array() 
)
protected

Finds the base themes for the specific theme.

Parameters
array$themesAn array of available themes.
string$themeThe name of the theme whose base we are looking for.
array$used_themes(optional) A recursion parameter preventing endless loops. Defaults to an empty array.
Returns
array An array of base themes.

Referenced by ThemeHandler\getBaseThemes().

Here is the caller graph for this function:

getBaseThemes ( array  $themes,
  $theme 
)

{Finds all the base themes for the specified theme.Themes can inherit templates and function implementations from earlier themes.

Parameters
\Drupal\Core\Extension\Extension[]$themes An array of available themes.
string$themeThe name of the theme whose base we are looking for.
Returns
array Returns an array of all of the theme's ancestors; the first element's value will be NULL if an error occurred.
}

Implements ThemeHandlerInterface.

References ThemeHandler\doGetBaseThemes().

Referenced by ThemeHandler\rebuildThemeData().

Here is the call graph for this function:

Here is the caller graph for this function:

getDefault ( )

{Returns the default theme.

Returns
string The default theme.
}

Implements ThemeHandlerInterface.

References Drupal\configFactory().

Here is the call graph for this function:

getExtensionDiscovery ( )
protected

Returns an extension discovery object.

Returns
The extension discovery object.

References Drupal\root().

Referenced by ThemeHandler\rebuildThemeData().

Here is the call graph for this function:

Here is the caller graph for this function:

getName (   $theme)

{Gets the human readable name of a given theme.

Parameters
string$themeThe machine name of the theme which title should be shown.
Returns
string Returns the human readable name of the theme.
}

Implements ThemeHandlerInterface.

References ThemeHandler\listInfo().

Here is the call graph for this function:

getTheme (   $name)

{Returns a theme extension object from the currently active theme list.

Parameters
string$nameThe name of the theme to return.
Returns
An extension object.
Exceptions
\InvalidArgumentExceptionThrown when the requested theme does not exist.
}

Implements ThemeHandlerInterface.

References ThemeHandler\listInfo().

Here is the call graph for this function:

getThemeDirectories ( )

{Returns an array of directories for all installed themes.Useful for tasks such as finding a file that exists in all theme directories.

Returns
array
}

Implements ThemeHandlerInterface.

References ThemeHandler\listInfo(), and Drupal\root().

Here is the call graph for this function:

hasUi (   $name)

{Determines if a theme should be shown in the user interface.To be shown in the UI the theme has to be installed. If the theme is hidden it will not be shown unless it is the default or admin theme.

Parameters
string$nameThe name of the theme to check.
Returns
bool TRUE if the theme should be shown in the UI, FALSE if not.
}

Implements ThemeHandlerInterface.

References Drupal\configFactory(), and ThemeHandler\listInfo().

Here is the call graph for this function:

install ( array  $theme_list,
  $install_dependencies = TRUE 
)

{Installs a given list of themes.

Parameters
array$theme_listAn array of theme names.
bool$install_dependencies(optional) If TRUE, dependencies will automatically be installed in the correct order. This incurs a significant performance cost, so use FALSE if you know $theme_list is already complete and in the correct order.
Returns
bool Whether any of the given themes have been installed.
Exceptions
\Drupal\Core\Extension\ExtensionNameLengthExceptionThrown when the theme name is to long
Deprecated:
in Drupal 8.0.x-dev and will be removed before Drupal 9.0.0. Use the theme_installer service instead.
See Also
::install
}

Implements ThemeHandlerInterface.

listInfo ( )

{Returns a list of currently installed themes.

Returns
[] An associative array of the currently installed themes. The keys are the themes' machine names and the values are objects having the following properties:
  • filename: The filepath and name of the .info.yml file.
  • name: The machine name of the theme.
  • status: 1 for installed, 0 for uninstalled themes.
  • info: The contents of the .info.yml file.
  • stylesheets: A two dimensional array, using the first key for the media attribute (e.g. 'all'), the second for the name of the file (e.g. style.css). The value is a complete filepath (e.g. themes/bartik/style.css). Not set if no stylesheets are defined in the .info.yml file.
  • scripts: An associative array of JavaScripts, using the filename as key and the complete filepath as value. Not set if no scripts are defined in the .info.yml file.
  • prefix: The base theme engine prefix.
  • engine: The machine name of the theme engine.
  • base_theme: If this is a sub-theme, the machine name of the base theme defined in the .info.yml file. Otherwise, the element is not set.
  • base_themes: If this is a sub-theme, an associative array of the base-theme ancestors of this theme, starting with this theme's base theme, then the base theme's own base theme, etc. Each entry has an array key equal to the theme's machine name, and a value equal to the human-readable theme name; if a theme with matching machine name does not exist in the system, the value will instead be NULL (and since the system would not know whether that theme itself has a base theme, that will end the array of base themes). This is not set if the theme is not a sub-theme.
  • sub_themes: An associative array of themes on the system that are either direct sub-themes (that is, they declare this theme to be their base theme), direct sub-themes of sub-themes, etc. The keys are the themes' machine names, and the values are the themes' human-readable names. This element is not set if there are no themes on the system that declare this theme as their base theme.
}

Implements ThemeHandlerInterface.

References ThemeHandler\addTheme(), ThemeHandler\refreshInfo(), Drupal\state(), and ThemeHandler\systemThemeList().

Referenced by ThemeHandler\getName(), ThemeHandler\getTheme(), ThemeHandler\getThemeDirectories(), ThemeHandler\hasUi(), ThemeHandler\setDefault(), and ThemeHandler\themeExists().

Here is the call graph for this function:

Here is the caller graph for this function:

rebuildThemeData ( )

{Scans and collects theme extension data and their engines.

Returns
[] An associative array of theme extensions.
}

Implements ThemeHandlerInterface.

References Drupal\configFactory(), ThemeHandler\getBaseThemes(), ThemeHandler\getExtensionDiscovery(), Drupal\moduleHandler(), and Drupal\state().

Referenced by ThemeHandler\refreshInfo().

Here is the call graph for this function:

Here is the caller graph for this function:

refreshInfo ( )

{Refreshes the theme info data of currently installed themes.Modules can alter theme info, so this is typically called after a module has been installed or uninstalled.}

Implements ThemeHandlerInterface.

References ThemeHandler\addTheme(), Drupal\configFactory(), ThemeHandler\rebuildThemeData(), ThemeHandler\reset(), and Drupal\state().

Referenced by ThemeHandler\listInfo().

Here is the call graph for this function:

Here is the caller graph for this function:

reset ( )

{Resets the internal state of the theme handler.}

Implements ThemeHandlerInterface.

References ThemeHandler\systemListReset().

Referenced by ThemeHandler\refreshInfo().

Here is the call graph for this function:

Here is the caller graph for this function:

setDefault (   $name)

{Sets a new default theme.

Parameters
string$themeThe new default theme.
Returns
$this
}

Implements ThemeHandlerInterface.

References Drupal\configFactory(), and ThemeHandler\listInfo().

Here is the call graph for this function:

systemListReset ( )
protected

Wraps system_list_reset().

Referenced by ThemeHandler\reset().

Here is the caller graph for this function:

systemThemeList ( )
protected

Wraps system_list().

Returns
array A list of themes keyed by name.

Referenced by ThemeHandler\listInfo().

Here is the caller graph for this function:

themeExists (   $theme)

{Determines whether a given theme is installed.

Parameters
string$themeThe name of the theme (without the .theme extension).
Returns
bool TRUE if the theme is installed.
}

Implements ThemeHandlerInterface.

References ThemeHandler\listInfo().

Here is the call graph for this function:

uninstall ( array  $theme_list)

{Uninstalls a given list of themes.Uninstalling a theme removes all related configuration (like blocks) and invokes the 'themes_uninstalled' hook.

Parameters
array$theme_listThe themes to uninstall.
Exceptions
\InvalidArgumentExceptionThrown when you uninstall an not installed theme.
See Also
hook_themes_uninstalled()
Deprecated:
in Drupal 8.0.x-dev and will be removed before Drupal 9.0.0. Use the theme_installer service instead.
See Also
::uninstall
}

Implements ThemeHandlerInterface.

References Drupal\service().

Here is the call graph for this function:

Field Documentation

$defaultFeatures
protected
Initial value:
= array(
'favicon',
'logo',
'node_user_picture',
'comment_user_picture',
'comment_user_verification',
)

The documentation for this class was generated from the following file: