ModuleHandlerInterface.php

You are here

Contains Drupal\Core\Extension\ModuleHandlerInterface.

Namespace

Drupal\Core\Extension

Interfaces

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

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. * Sets an explicit list of currently active modules.
  53. *
  54. * @param \Drupal\Core\Extension\Extension[] $module_list
  55. * An associative array whose keys are the names of the modules and whose
  56. * values are Extension objects.
  57. */
  58. public function setModuleList(array $module_list = array());
  59. /**
  60. * Adds a module to the list of currently active modules.
  61. *
  62. * @param string $name
  63. * The module name; e.g., 'node'.
  64. * @param string $path
  65. * The module path; e.g., 'core/modules/node'.
  66. */
  67. public function addModule($name, $path);
  68. /**
  69. * Adds an installation profile to the list of currently active modules.
  70. *
  71. * @param string $name
  72. * The profile name; e.g., 'standard'.
  73. * @param string $path
  74. * The profile path; e.g., 'core/profiles/standard'.
  75. */
  76. public function addProfile($name, $path);
  77. /**
  78. * Determines which modules require and are required by each module.
  79. *
  80. * @param array $modules
  81. * An array of module objects keyed by module name. Each object contains
  82. * information discovered during a Drupal\Core\Extension\ExtensionDiscovery
  83. * scan.
  84. *
  85. * @return
  86. * The same array with the new keys for each module:
  87. * - requires: An array with the keys being the modules that this module
  88. * requires.
  89. * - required_by: An array with the keys being the modules that will not work
  90. * without this module.
  91. *
  92. * @see \Drupal\Core\Extension\ExtensionDiscovery
  93. */
  94. public function buildModuleDependencies(array $modules);
  95. /**
  96. * Determines whether a given module is enabled.
  97. *
  98. * @param string $module
  99. * The name of the module (without the .module extension).
  100. *
  101. * @return bool
  102. * TRUE if the module is both installed and enabled.
  103. */
  104. public function moduleExists($module);
  105. /**
  106. * Loads an include file for each enabled module.
  107. *
  108. * @param string $type
  109. * The include file's type (file extension).
  110. * @param string $name
  111. * (optional) The base file name (without the $type extension). If omitted,
  112. * each module's name is used; i.e., "$module.$type" by default.
  113. */
  114. public function loadAllIncludes($type, $name = NULL);
  115. /**
  116. * Loads a module include file.
  117. *
  118. * Examples:
  119. * @code
  120. * // Load node.admin.inc from the node module.
  121. * $this->loadInclude('node', 'inc', 'node.admin');
  122. * // Load content_types.inc from the node module.
  123. * $this->loadInclude('node', 'inc', ''content_types');
  124. * @endcode
  125. *
  126. * @param string $module
  127. * The module to which the include file belongs.
  128. * @param string $type
  129. * The include file's type (file extension).
  130. * @param string $name
  131. * (optional) The base file name (without the $type extension). If omitted,
  132. * $module is used; i.e., resulting in "$module.$type" by default.
  133. *
  134. * @return string|false
  135. * The name of the included file, if successful; FALSE otherwise.
  136. */
  137. public function loadInclude($module, $type, $name = NULL);
  138. /**
  139. * Retrieves a list of hooks that are declared through hook_hook_info().
  140. *
  141. * @return array
  142. * An associative array whose keys are hook names and whose values are an
  143. * associative array containing a group name. The structure of the array
  144. * is the same as the return value of hook_hook_info().
  145. *
  146. * @see hook_hook_info()
  147. */
  148. public function getHookInfo();
  149. /**
  150. * Determines which modules are implementing a hook.
  151. *
  152. * @param string $hook
  153. * The name of the hook (e.g. "help" or "menu").
  154. *
  155. * @return array
  156. * An array with the names of the modules which are implementing this hook.
  157. */
  158. public function getImplementations($hook);
  159. /**
  160. * Resets the cached list of hook implementations.
  161. */
  162. public function resetImplementations();
  163. /**
  164. * Returns whether a given module implements a given hook.
  165. *
  166. * @param string $module
  167. * The name of the module (without the .module extension).
  168. * @param string $hook
  169. * The name of the hook (e.g. "help" or "menu").
  170. *
  171. * @return bool
  172. * TRUE if the module is both installed and enabled, and the hook is
  173. * implemented in that module.
  174. */
  175. public function implementsHook($module, $hook);
  176. /**
  177. * Invokes a hook in a particular module.
  178. *
  179. * @param string $module
  180. * The name of the module (without the .module extension).
  181. * @param string $hook
  182. * The name of the hook to invoke.
  183. * @param ...
  184. * Arguments to pass to the hook implementation.
  185. *
  186. * @return mixed
  187. * The return value of the hook implementation.
  188. */
  189. public function invoke($module, $hook, array $args = array());
  190. /**
  191. * Invokes a hook in all enabled modules that implement it.
  192. *
  193. * @param string $hook
  194. * The name of the hook to invoke.
  195. * @param array $args
  196. * Arguments to pass to the hook.
  197. *
  198. * @return array
  199. * An array of return values of the hook implementations. If modules return
  200. * arrays from their implementations, those are merged into one array.
  201. */
  202. public function invokeAll($hook, array $args = array());
  203. /**
  204. * Passes alterable variables to specific hook_TYPE_alter() implementations.
  205. *
  206. * This dispatch function hands off the passed-in variables to type-specific
  207. * hook_TYPE_alter() implementations in modules. It ensures a consistent
  208. * interface for all altering operations.
  209. *
  210. * A maximum of 2 alterable arguments is supported. In case more arguments need
  211. * to be passed and alterable, modules provide additional variables assigned by
  212. * reference in the last $context argument:
  213. * @code
  214. * $context = array(
  215. * 'alterable' => &$alterable,
  216. * 'unalterable' => $unalterable,
  217. * 'foo' => 'bar',
  218. * );
  219. * $this->alter('mymodule_data', $alterable1, $alterable2, $context);
  220. * @endcode
  221. *
  222. * Note that objects are always passed by reference in PHP5. If it is absolutely
  223. * required that no implementation alters a passed object in $context, then an
  224. * object needs to be cloned:
  225. * @code
  226. * $context = array(
  227. * 'unalterable_object' => clone $object,
  228. * );
  229. * $this->alter('mymodule_data', $data, $context);
  230. * @endcode
  231. *
  232. * @param string|array $type
  233. * A string describing the type of the alterable $data. 'form', 'links',
  234. * 'node_content', and so on are several examples. Alternatively can be an
  235. * array, in which case hook_TYPE_alter() is invoked for each value in the
  236. * array, ordered first by module, and then for each module, in the order of
  237. * values in $type. For example, when Form API is using $this->alter() to
  238. * execute both hook_form_alter() and hook_form_FORM_ID_alter()
  239. * implementations, it passes array('form', 'form_' . $form_id) for $type.
  240. * @param mixed $data
  241. * The variable that will be passed to hook_TYPE_alter() implementations to be
  242. * altered. The type of this variable depends on the value of the $type
  243. * argument. For example, when altering a 'form', $data will be a structured
  244. * array. When altering a 'profile', $data will be an object.
  245. * @param mixed $context1
  246. * (optional) An additional variable that is passed by reference.
  247. * @param mixed $context2
  248. * (optional) An additional variable that is passed by reference. If more
  249. * context needs to be provided to implementations, then this should be an
  250. * associative array as described above.
  251. */
  252. public function alter($type, &$data, &$context1 = NULL, &$context2 = NULL);
  253. /**
  254. * Installs a given list of modules.
  255. *
  256. * Order of events:
  257. * - Gather and add module dependencies to $module_list (if applicable).
  258. * - For each module that is being installed:
  259. * - Invoke hook_module_preinstall().
  260. * - Install module schema and update system registries and caches.
  261. * - Invoke hook_install() and add it to the list of installed modules.
  262. * - Invoke hook_modules_installed().
  263. *
  264. * @param array $module_list
  265. * An array of module names.
  266. * @param bool $enable_dependencies
  267. * (optional) If TRUE, dependencies will automatically be installed in the
  268. * correct order. This incurs a significant performance cost, so use FALSE
  269. * if you know $module_list is already complete.
  270. *
  271. * @return bool
  272. * FALSE if one or more dependencies are missing, TRUE otherwise.
  273. *
  274. * @see hook_module_preinstall()
  275. * @see hook_install()
  276. * @see hook_modules_installed()
  277. */
  278. public function install(array $module_list, $enable_dependencies = TRUE);
  279. /**
  280. * Uninstalls a given list of disabled modules.
  281. *
  282. * @param array $module_list
  283. * The modules to uninstall.
  284. * @param bool $uninstall_dependents
  285. * (optional) If TRUE, dependent modules will automatically be uninstalled
  286. * in the correct order. This incurs a significant performance cost, so use
  287. * FALSE if you know $module_list is already complete.
  288. *
  289. * @return bool
  290. * FALSE if one or more dependencies are missing, TRUE otherwise.
  291. *
  292. * @see hook_module_preuninstall()
  293. * @see hook_uninstall()
  294. * @see hook_modules_uninstalled()
  295. */
  296. public function uninstall(array $module_list, $uninstall_dependents = TRUE);
  297. /**
  298. * Returns an array of directories for all enabled modules. Useful for
  299. * tasks such as finding a file that exists in all module directories.
  300. *
  301. * @return array
  302. */
  303. public function getModuleDirectories();
  304. }