ThemeManagerInterface.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. namespace Drupal\Core\Theme;
  3. /**
  4. * Provides a high level access to the active theme and methods to use it.
  5. *
  6. * Beside the active theme it provides a wrapper around _theme as well as the
  7. * alter functionality for themes.
  8. */
  9. interface ThemeManagerInterface {
  10. /**
  11. * Generates themed output.
  12. *
  13. * See the @link themeable Default theme implementations topic @endlink for
  14. * details.
  15. *
  16. * @param string $hook
  17. * The name of the theme hook to call.
  18. * @param array $variables
  19. * An associative array of theme variables.
  20. *
  21. * @return string|\Drupal\Component\Render\MarkupInterface
  22. * The rendered output, or a Markup object.
  23. */
  24. public function render($hook, array $variables);
  25. /**
  26. * Returns the active theme object.
  27. *
  28. * @return \Drupal\Core\Theme\ActiveTheme
  29. */
  30. public function getActiveTheme();
  31. /**
  32. * Determines whether there is an active theme.
  33. *
  34. * @return bool
  35. */
  36. public function hasActiveTheme();
  37. /**
  38. * Resets the current active theme.
  39. *
  40. * Note: This method should not be used in common cases, just in special cases
  41. * like tests.
  42. *
  43. * @return $this
  44. */
  45. public function resetActiveTheme();
  46. /**
  47. * Sets the current active theme manually.
  48. *
  49. * Note: This method should not be used in common cases, just in special cases
  50. * like tests.
  51. *
  52. * @param \Drupal\Core\Theme\ActiveTheme $active_theme
  53. * The new active theme.
  54. * @return $this
  55. */
  56. public function setActiveTheme(ActiveTheme $active_theme);
  57. /**
  58. * Passes alterable variables to specific $theme_TYPE_alter() implementations.
  59. *
  60. * Executes an alter hook on the current theme. It also invokes alter hooks
  61. * for all base themes.
  62. *
  63. * $theme specifies the theme name of the active theme and all its base
  64. * themes.
  65. *
  66. * This dispatch function hands off the passed-in variables to type-specific
  67. * $theme_TYPE_alter() implementations in the active theme. It ensures a
  68. * consistent interface for all altering operations.
  69. *
  70. * A maximum of 2 alterable arguments is supported. In case more arguments
  71. * need to be passed and alterable, modules provide additional variables
  72. * assigned by reference in the last $context argument:
  73. * @code
  74. * $context = array(
  75. * 'alterable' => &$alterable,
  76. * 'unalterable' => $unalterable,
  77. * 'foo' => 'bar',
  78. * );
  79. * $this->alter('mymodule_data', $alterable1, $alterable2, $context);
  80. * @endcode
  81. *
  82. * Note that objects are always passed by reference in PHP5. If it is
  83. * absolutely required that no implementation alters a passed object in
  84. * $context, then an object needs to be cloned:
  85. * @code
  86. * $context = array(
  87. * 'unalterable_object' => clone $object,
  88. * );
  89. * $this->alter('mymodule_data', $data, $context);
  90. * @endcode
  91. *
  92. * @param string|array $type
  93. * A string describing the type of the alterable $data. 'form', 'links',
  94. * 'node_content', and so on are several examples. Alternatively can be an
  95. * array, in which case $theme_TYPE_alter() is invoked for each value in the
  96. * array. When Form API is using $this->alter() to
  97. * execute both $theme_form_alter() and $theme_form_FORM_ID_alter()
  98. * implementations, it passes array('form', 'form_' . $form_id) for $type.
  99. * @param mixed $data
  100. * The variable that will be passed to $theme_TYPE_alter() implementations
  101. * to be altered. The type of this variable depends on the value of the
  102. * $type argument. For example, when altering a 'form', $data will be a
  103. * structured array. When altering a 'profile', $data will be an object.
  104. * @param mixed $context1
  105. * (optional) An additional variable that is passed by reference.
  106. * @param mixed $context2
  107. * (optional) An additional variable that is passed by reference. If more
  108. * context needs to be provided to implementations, then this should be an
  109. * associative array as described above.
  110. *
  111. * @see \Drupal\Core\Extension\ModuleHandlerInterface
  112. */
  113. public function alter($type, &$data, &$context1 = NULL, &$context2 = NULL);
  114. /**
  115. * Provides an alter hook for a specific theme.
  116. *
  117. * Similar to ::alter, it also invokes the alter hooks for the base themes.
  118. *
  119. * @param \Drupal\Core\Theme\ActiveTheme $theme
  120. * A manually specified theme.
  121. * @param string|array $type
  122. * A string describing the type of the alterable $data.
  123. * @param mixed $data
  124. * The variable that will be passed to $theme_TYPE_alter() implementations
  125. * @param mixed $context1
  126. * (optional) An additional variable that is passed by reference.
  127. * @param mixed $context2
  128. * (optional) An additional variable that is passed by reference.
  129. *
  130. * @see ::alter
  131. */
  132. public function alterForTheme(ActiveTheme $theme, $type, &$data, &$context1 = NULL, &$context2 = NULL);
  133. }