3 namespace Drupal\Core\Theme;
6 * Provides a high level access to the active theme and methods to use it.
8 * Beside the active theme it provides a wrapper around _theme as well as the
9 * alter functionality for themes.
11 interface ThemeManagerInterface {
14 * Generates themed output.
16 * See the @link themeable Default theme implementations topic @endlink for
20 * The name of the theme hook to call.
21 * @param array $variables
22 * An associative array of theme variables.
24 * @return string|\Drupal\Component\Render\MarkupInterface
25 * The rendered output, or a Markup object.
27 public function render($hook, array $variables);
30 * Returns the active theme object.
32 * @return \Drupal\Core\Theme\ActiveTheme
34 public function getActiveTheme();
37 * Determines whether there is an active theme.
41 public function hasActiveTheme();
44 * Resets the current active theme.
46 * Note: This method should not be used in common cases, just in special cases
51 public function resetActiveTheme();
54 * Sets the current active theme manually.
56 * Note: This method should not be used in common cases, just in special cases
59 * @param \Drupal\Core\Theme\ActiveTheme $active_theme
60 * The new active theme.
63 public function setActiveTheme(ActiveTheme $active_theme);
66 * Passes alterable variables to specific $theme_TYPE_alter() implementations.
68 * Executes an alter hook on the current theme. It also invokes alter hooks
69 * for all base themes.
71 * $theme specifies the theme name of the active theme and all its base
74 * This dispatch function hands off the passed-in variables to type-specific
75 * $theme_TYPE_alter() implementations in the active theme. It ensures a
76 * consistent interface for all altering operations.
78 * A maximum of 2 alterable arguments is supported. In case more arguments
79 * need to be passed and alterable, modules provide additional variables
80 * assigned by reference in the last $context argument:
83 * 'alterable' => &$alterable,
84 * 'unalterable' => $unalterable,
87 * $this->alter('mymodule_data', $alterable1, $alterable2, $context);
90 * Note that objects are always passed by reference in PHP5. If it is
91 * absolutely required that no implementation alters a passed object in
92 * $context, then an object needs to be cloned:
95 * 'unalterable_object' => clone $object,
97 * $this->alter('mymodule_data', $data, $context);
100 * @param string|array $type
101 * A string describing the type of the alterable $data. 'form', 'links',
102 * 'node_content', and so on are several examples. Alternatively can be an
103 * array, in which case $theme_TYPE_alter() is invoked for each value in the
104 * array. When Form API is using $this->alter() to
105 * execute both $theme_form_alter() and $theme_form_FORM_ID_alter()
106 * implementations, it passes array('form', 'form_' . $form_id) for $type.
108 * The variable that will be passed to $theme_TYPE_alter() implementations
109 * to be altered. The type of this variable depends on the value of the
110 * $type argument. For example, when altering a 'form', $data will be a
111 * structured array. When altering a 'profile', $data will be an object.
112 * @param mixed $context1
113 * (optional) An additional variable that is passed by reference.
114 * @param mixed $context2
115 * (optional) An additional variable that is passed by reference. If more
116 * context needs to be provided to implementations, then this should be an
117 * associative array as described above.
119 * @see \Drupal\Core\Extension\ModuleHandlerInterface
121 public function alter($type, &$data, &$context1 = NULL, &$context2 = NULL);
124 * Provides an alter hook for a specific theme.
126 * Similar to ::alter, it also invokes the alter hooks for the base themes.
128 * @param \Drupal\Core\Theme\ActiveTheme $theme
129 * A manually specified theme.
130 * @param string|array $type
131 * A string describing the type of the alterable $data.
133 * The variable that will be passed to $theme_TYPE_alter() implementations
134 * @param mixed $context1
135 * (optional) An additional variable that is passed by reference.
136 * @param mixed $context2
137 * (optional) An additional variable that is passed by reference.
141 public function alterForTheme(ActiveTheme $theme, $type, &$data, &$context1 = NULL, &$context2 = NULL);