Contains Drupal\Core\Extension\ModuleHandlerInterface.

Namespace

Drupal\Core\Extension

File

core/lib/Drupal/Core/Extension/ModuleHandlerInterface.php
View source
  1. <?php
  2. /**
  3. * @file
  4. * Contains Drupal\Core\Extension\ModuleHandlerInterface.
  5. */
  6. namespace Drupal\Core\Extension;
  7. /**
  8. * Interface for classes that manage a set of enabled modules.
  9. *
  10. * Classes implementing this interface work with a fixed list of modules and are
  11. * responsible for loading module files and maintaining information about module
  12. * dependencies and hook implementations.
  13. */
  14. interface ModuleHandlerInterface {
  15. /**
  16. * Includes a module's .module file.
  17. *
  18. * This prevents including a module more than once.
  19. *
  20. * @param string $name
  21. * The name of the module to load.
  22. *
  23. * @return bool
  24. * TRUE if the item is loaded or has already been loaded.
  25. */
  26. public function load($name);
  27. /**
  28. * Loads all enabled modules.
  29. */
  30. public function loadAll();
  31. /**
  32. * Returns whether all modules have been loaded.
  33. *
  34. * @return bool
  35. * A Boolean indicating whether all modules have been loaded. This means all
  36. * modules; the load status of bootstrap modules cannot be checked.
  37. */
  38. public function isLoaded();
  39. /**
  40. * Reloads all enabled modules.
  41. */
  42. public function reload();
  43. /**
  44. * Returns the list of currently active modules.
  45. *
  46. * @return \Drupal\Core\Extension\Extension[]
  47. * An associative array whose keys are the names of the modules and whose
  48. * values are Extension objects.
  49. */
  50. public function getModuleList();
  51. /**
  52. * Returns a module extension object from the currently active modules list.
  53. *
  54. * @param string $name
  55. * The name of the module to return.
  56. *
  57. * @return \Drupal\Core\Extension\Extension
  58. * An extension object.
  59. *
  60. * @throws \InvalidArgumentException
  61. * Thrown when the requested module does not exist.
  62. */
  63. public function getModule($name);
  64. /**
  65. * Sets an explicit list of currently active modules.
  66. *
  67. * @param \Drupal\Core\Extension\Extension[] $module_list
  68. * An associative array whose keys are the names of the modules and whose
  69. * values are Extension objects.
  70. */
  71. public function setModuleList(array $module_list = array());
  72. /**
  73. * Adds a module to the list of currently active modules.
  74. *
  75. * @param string $name
  76. * The module name; e.g., 'node'.
  77. * @param string $path
  78. * The module path; e.g., 'core/modules/node'.
  79. */
  80. public function addModule($name, $path);
  81. /**
  82. * Adds an installation profile to the list of currently active modules.
  83. *
  84. * @param string $name
  85. * The profile name; e.g., 'standard'.
  86. * @param string $path
  87. * The profile path; e.g., 'core/profiles/standard'.
  88. */
  89. public function addProfile($name, $path);
  90. /**
  91. * Determines which modules require and are required by each module.
  92. *
  93. * @param array $modules
  94. * An array of module objects keyed by module name. Each object contains
  95. * information discovered during a Drupal\Core\Extension\ExtensionDiscovery
  96. * scan.
  97. *
  98. * @return
  99. * The same array with the new keys for each module:
  100. * - requires: An array with the keys being the modules that this module
  101. * requires.
  102. * - required_by: An array with the keys being the modules that will not work
  103. * without this module.
  104. *
  105. * @see \Drupal\Core\Extension\ExtensionDiscovery
  106. */
  107. public function buildModuleDependencies(array $modules);
  108. /**
  109. * Determines whether a given module is enabled.
  110. *
  111. * @param string $module
  112. * The name of the module (without the .module extension).
  113. *
  114. * @return bool
  115. * TRUE if the module is both installed and enabled.
  116. */
  117. public function moduleExists($module);
  118. /**
  119. * Loads an include file for each enabled module.
  120. *
  121. * @param string $type
  122. * The include file's type (file extension).
  123. * @param string $name
  124. * (optional) The base file name (without the $type extension). If omitted,
  125. * each module's name is used; i.e., "$module.$type" by default.
  126. */
  127. public function loadAllIncludes($type, $name = NULL);
  128. /**
  129. * Loads a module include file.
  130. *
  131. * Examples:
  132. * @code
  133. * // Load node.admin.inc from the node module.
  134. * $this->loadInclude('node', 'inc', 'node.admin');
  135. * // Load content_types.inc from the node module.
  136. * $this->loadInclude('node', 'inc', ''content_types');
  137. * @endcode
  138. *
  139. * @param string $module
  140. * The module to which the include file belongs.
  141. * @param string $type
  142. * The include file's type (file extension).
  143. * @param string $name
  144. * (optional) The base file name (without the $type extension). If omitted,
  145. * $module is used; i.e., resulting in "$module.$type" by default.
  146. *
  147. * @return string|false
  148. * The name of the included file, if successful; FALSE otherwise.
  149. */
  150. public function loadInclude($module, $type, $name = NULL);
  151. /**
  152. * Retrieves a list of hooks that are declared through hook_hook_info().
  153. *
  154. * @return array
  155. * An associative array whose keys are hook names and whose values are an
  156. * associative array containing a group name. The structure of the array
  157. * is the same as the return value of hook_hook_info().
  158. *
  159. * @see hook_hook_info()
  160. */
  161. public function getHookInfo();
  162. /**
  163. * Determines which modules are implementing a hook.
  164. *
  165. * @param string $hook
  166. * The name of the hook (e.g. "help" or "menu").
  167. *
  168. * @return array
  169. * An array with the names of the modules which are implementing this hook.
  170. */
  171. public function getImplementations($hook);
  172. /**
  173. * Write the hook implementation info to the cache.
  174. */
  175. public function writeCache();
  176. /**
  177. * Resets the cached list of hook implementations.
  178. */
  179. public function resetImplementations();
  180. /**
  181. * Returns whether a given module implements a given hook.
  182. *
  183. * @param string $module
  184. * The name of the module (without the .module extension).
  185. * @param string $hook
  186. * The name of the hook (e.g. "help" or "menu").
  187. *
  188. * @return bool
  189. * TRUE if the module is both installed and enabled, and the hook is
  190. * implemented in that module.
  191. */
  192. public function implementsHook($module, $hook);
  193. /**
  194. * Invokes a hook in a particular module.
  195. *
  196. * @param string $module
  197. * The name of the module (without the .module extension).
  198. * @param string $hook
  199. * The name of the hook to invoke.
  200. * @param ...
  201. * Arguments to pass to the hook implementation.
  202. *
  203. * @return mixed
  204. * The return value of the hook implementation.
  205. */
  206. public function invoke($module, $hook, array $args = array());
  207. /**
  208. * Invokes a hook in all enabled modules that implement it.
  209. *
  210. * @param string $hook
  211. * The name of the hook to invoke.
  212. * @param array $args
  213. * Arguments to pass to the hook.
  214. *
  215. * @return array
  216. * An array of return values of the hook implementations. If modules return
  217. * arrays from their implementations, those are merged into one array.
  218. */
  219. public function invokeAll($hook, array $args = array());
  220. /**
  221. * Passes alterable variables to specific hook_TYPE_alter() implementations.
  222. *
  223. * This dispatch function hands off the passed-in variables to type-specific
  224. * hook_TYPE_alter() implementations in modules. It ensures a consistent
  225. * interface for all altering operations.
  226. *
  227. * A maximum of 2 alterable arguments is supported. In case more arguments need
  228. * to be passed and alterable, modules provide additional variables assigned by
  229. * reference in the last $context argument:
  230. * @code
  231. * $context = array(
  232. * 'alterable' => &$alterable,
  233. * 'unalterable' => $unalterable,
  234. * 'foo' => 'bar',
  235. * );
  236. * $this->alter('mymodule_data', $alterable1, $alterable2, $context);
  237. * @endcode
  238. *
  239. * Note that objects are always passed by reference in PHP5. If it is absolutely
  240. * required that no implementation alters a passed object in $context, then an
  241. * object needs to be cloned:
  242. * @code
  243. * $context = array(
  244. * 'unalterable_object' => clone $object,
  245. * );
  246. * $this->alter('mymodule_data', $data, $context);
  247. * @endcode
  248. *
  249. * @param string|array $type
  250. * A string describing the type of the alterable $data. 'form', 'links',
  251. * 'node_content', and so on are several examples. Alternatively can be an
  252. * array, in which case hook_TYPE_alter() is invoked for each value in the
  253. * array, ordered first by module, and then for each module, in the order of
  254. * values in $type. For example, when Form API is using $this->alter() to
  255. * execute both hook_form_alter() and hook_form_FORM_ID_alter()
  256. * implementations, it passes array('form', 'form_' . $form_id) for $type.
  257. * @param mixed $data
  258. * The variable that will be passed to hook_TYPE_alter() implementations to be
  259. * altered. The type of this variable depends on the value of the $type
  260. * argument. For example, when altering a 'form', $data will be a structured
  261. * array. When altering a 'profile', $data will be an object.
  262. * @param mixed $context1
  263. * (optional) An additional variable that is passed by reference.
  264. * @param mixed $context2
  265. * (optional) An additional variable that is passed by reference. If more
  266. * context needs to be provided to implementations, then this should be an
  267. * associative array as described above.
  268. */
  269. public function alter($type, &$data, &$context1 = NULL, &$context2 = NULL);
  270. /**
  271. * Returns an array of directories for all enabled modules. Useful for
  272. * tasks such as finding a file that exists in all module directories.
  273. *
  274. * @return array
  275. */
  276. public function getModuleDirectories();
  277. /**
  278. * Gets the human readable name of a given module.
  279. *
  280. * @param string $module
  281. * The machine name of the module which title should be shown.
  282. *
  283. * @return string
  284. * Returns the human readable name of the module or the machine name passed
  285. * in if no matching module is found.
  286. */
  287. public function getName($module);
  288. }

Interfaces

Namesort descending Description
ModuleHandlerInterface Interface for classes that manage a set of enabled modules.