ThemeManagerInterface.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. *
  55. * @return $this
  56. */
  57. public function setActiveTheme(ActiveTheme $active_theme);
  58. /**
  59. * Passes alterable variables to specific $theme_TYPE_alter() implementations.
  60. *
  61. * Executes an alter hook on the current theme. It also invokes alter hooks
  62. * for all base themes.
  63. *
  64. * $theme specifies the theme name of the active theme and all its base
  65. * themes.
  66. *
  67. * This dispatch function hands off the passed-in variables to type-specific
  68. * $theme_TYPE_alter() implementations in the active theme. It ensures a
  69. * consistent interface for all altering operations.
  70. *
  71. * A maximum of 2 alterable arguments is supported. In case more arguments
  72. * need to be passed and alterable, modules provide additional variables
  73. * assigned by reference in the last $context argument:
  74. * @code
  75. * $context = array(
  76. * 'alterable' => &$alterable,
  77. * 'unalterable' => $unalterable,
  78. * 'foo' => 'bar',
  79. * );
  80. * $this->alter('mymodule_data', $alterable1, $alterable2, $context);
  81. * @endcode
  82. *
  83. * Note that objects are always passed by reference. If it is absolutely
  84. * required that no implementation alters a passed object in $context, then an
  85. * object needs to be cloned:
  86. * @code
  87. * $context = array(
  88. * 'unalterable_object' => clone $object,
  89. * );
  90. * $this->alter('mymodule_data', $data, $context);
  91. * @endcode
  92. *
  93. * @param string|array $type
  94. * A string describing the type of the alterable $data. 'form', 'links',
  95. * 'node_content', and so on are several examples. Alternatively can be an
  96. * array, in which case $theme_TYPE_alter() is invoked for each value in the
  97. * array. When Form API is using $this->alter() to
  98. * execute both $theme_form_alter() and $theme_form_FORM_ID_alter()
  99. * implementations, it passes array('form', 'form_' . $form_id) for $type.
  100. * @param mixed $data
  101. * The variable that will be passed to $theme_TYPE_alter() implementations
  102. * to be altered. The type of this variable depends on the value of the
  103. * $type argument. For example, when altering a 'form', $data will be a
  104. * structured array. When altering a 'profile', $data will be an object.
  105. * @param mixed $context1
  106. * (optional) An additional variable that is passed by reference.
  107. * @param mixed $context2
  108. * (optional) An additional variable that is passed by reference. If more
  109. * context needs to be provided to implementations, then this should be an
  110. * associative array as described above.
  111. *
  112. * @see \Drupal\Core\Extension\ModuleHandlerInterface
  113. */
  114. public function alter($type, &$data, &$context1 = NULL, &$context2 = NULL);
  115. /**
  116. * Provides an alter hook for a specific theme.
  117. *
  118. * Similar to ::alter, it also invokes the alter hooks for the base themes.
  119. *
  120. * @param \Drupal\Core\Theme\ActiveTheme $theme
  121. * A manually specified theme.
  122. * @param string|array $type
  123. * A string describing the type of the alterable $data.
  124. * @param mixed $data
  125. * The variable that will be passed to $theme_TYPE_alter() implementations
  126. * @param mixed $context1
  127. * (optional) An additional variable that is passed by reference.
  128. * @param mixed $context2
  129. * (optional) An additional variable that is passed by reference.
  130. *
  131. * @see ::alter
  132. */
  133. public function alterForTheme(ActiveTheme $theme, $type, &$data, &$context1 = NULL, &$context2 = NULL);
  134. }