PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/core/lib/Drupal/Core/Extension/ModuleHandlerInterface.php

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