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. * Write the hook implementation info to the cache.
  161. */
  162. public function writeCache();
  163. /**
  164. * Resets the cached list of hook implementations.
  165. */
  166. public function resetImplementations();
  167. /**
  168. * Returns whether a given module implements a given hook.
  169. *
  170. * @param string $module
  171. * The name of the module (without the .module extension).
  172. * @param string $hook
  173. * The name of the hook (e.g. "help" or "menu").
  174. *
  175. * @return bool
  176. * TRUE if the module is both installed and enabled, and the hook is
  177. * implemented in that module.
  178. */
  179. public function implementsHook($module, $hook);
  180. /**
  181. * Invokes a hook in a particular module.
  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 to invoke.
  187. * @param ...
  188. * Arguments to pass to the hook implementation.
  189. *
  190. * @return mixed
  191. * The return value of the hook implementation.
  192. */
  193. public function invoke($module, $hook, array $args = array());
  194. /**
  195. * Invokes a hook in all enabled modules that implement it.
  196. *
  197. * @param string $hook
  198. * The name of the hook to invoke.
  199. * @param array $args
  200. * Arguments to pass to the hook.
  201. *
  202. * @return array
  203. * An array of return values of the hook implementations. If modules return
  204. * arrays from their implementations, those are merged into one array.
  205. */
  206. public function invokeAll($hook, array $args = array());
  207. /**
  208. * Passes alterable variables to specific hook_TYPE_alter() implementations.
  209. *
  210. * This dispatch function hands off the passed-in variables to type-specific
  211. * hook_TYPE_alter() implementations in modules. It ensures a consistent
  212. * interface for all altering operations.
  213. *
  214. * A maximum of 2 alterable arguments is supported. In case more arguments need
  215. * to be passed and alterable, modules provide additional variables assigned by
  216. * reference in the last $context argument:
  217. * @code
  218. * $context = array(
  219. * 'alterable' => &$alterable,
  220. * 'unalterable' => $unalterable,
  221. * 'foo' => 'bar',
  222. * );
  223. * $this->alter('mymodule_data', $alterable1, $alterable2, $context);
  224. * @endcode
  225. *
  226. * Note that objects are always passed by reference in PHP5. If it is absolutely
  227. * required that no implementation alters a passed object in $context, then an
  228. * object needs to be cloned:
  229. * @code
  230. * $context = array(
  231. * 'unalterable_object' => clone $object,
  232. * );
  233. * $this->alter('mymodule_data', $data, $context);
  234. * @endcode
  235. *
  236. * @param string|array $type
  237. * A string describing the type of the alterable $data. 'form', 'links',
  238. * 'node_content', and so on are several examples. Alternatively can be an
  239. * array, in which case hook_TYPE_alter() is invoked for each value in the
  240. * array, ordered first by module, and then for each module, in the order of
  241. * values in $type. For example, when Form API is using $this->alter() to
  242. * execute both hook_form_alter() and hook_form_FORM_ID_alter()
  243. * implementations, it passes array('form', 'form_' . $form_id) for $type.
  244. * @param mixed $data
  245. * The variable that will be passed to hook_TYPE_alter() implementations to be
  246. * altered. The type of this variable depends on the value of the $type
  247. * argument. For example, when altering a 'form', $data will be a structured
  248. * array. When altering a 'profile', $data will be an object.
  249. * @param mixed $context1
  250. * (optional) An additional variable that is passed by reference.
  251. * @param mixed $context2
  252. * (optional) An additional variable that is passed by reference. If more
  253. * context needs to be provided to implementations, then this should be an
  254. * associative array as described above.
  255. */
  256. public function alter($type, &$data, &$context1 = NULL, &$context2 = NULL);
  257. /**
  258. * Installs a given list of modules.
  259. *
  260. * Order of events:
  261. * - Gather and add module dependencies to $module_list (if applicable).
  262. * - For each module that is being installed:
  263. * - Invoke hook_module_preinstall().
  264. * - Install module schema and update system registries and caches.
  265. * - Invoke hook_install() and add it to the list of installed modules.
  266. * - Invoke hook_modules_installed().
  267. *
  268. * @param array $module_list
  269. * An array of module names.
  270. * @param bool $enable_dependencies
  271. * (optional) If TRUE, dependencies will automatically be installed in the
  272. * correct order. This incurs a significant performance cost, so use FALSE
  273. * if you know $module_list is already complete.
  274. *
  275. * @return bool
  276. * FALSE if one or more dependencies are missing, TRUE otherwise.
  277. *
  278. * @see hook_module_preinstall()
  279. * @see hook_install()
  280. * @see hook_modules_installed()
  281. */
  282. public function install(array $module_list, $enable_dependencies = TRUE);
  283. /**
  284. * Uninstalls a given list of disabled modules.
  285. *
  286. * @param array $module_list
  287. * The modules to uninstall.
  288. * @param bool $uninstall_dependents
  289. * (optional) If TRUE, dependent modules will automatically be uninstalled
  290. * in the correct order. This incurs a significant performance cost, so use
  291. * FALSE if you know $module_list is already complete.
  292. *
  293. * @return bool
  294. * FALSE if one or more dependencies are missing, TRUE otherwise.
  295. *
  296. * @see hook_module_preuninstall()
  297. * @see hook_uninstall()
  298. * @see hook_modules_uninstalled()
  299. */
  300. public function uninstall(array $module_list, $uninstall_dependents = TRUE);
  301. /**
  302. * Returns an array of directories for all enabled modules. Useful for
  303. * tasks such as finding a file that exists in all module directories.
  304. *
  305. * @return array
  306. */
  307. public function getModuleDirectories();
  308. }