ModuleHandler
class ModuleHandler implements ModuleHandlerInterface (View source)
Class that manages modules in a Drupal installation.
Properties
| protected array | $loadedFiles | List of loaded files. |
|
| protected Extension[] | $moduleList | List of installed modules. |
|
| protected bool | $loaded | Boolean indicating whether modules have been loaded. |
|
| protected array | $implementations | List of hook implementations keyed by hook name. |
|
| protected true[] | $verified | List of hooks where the implementations have been "verified". |
|
| protected array | $hookInfo | Information returned by hook_hook_info() implementations. |
|
| protected CacheBackendInterface | $cacheBackend | Cache backend for storing module hook implementation information. |
|
| protected bool | $cacheNeedsWriting | Whether the cache needs to be written. |
|
| protected array | $alterFunctions | List of alter hook implementations keyed by hook name(s). |
|
| protected string | $root | The app root. |
|
| protected array | $includeFileKeys | A list of module include file keys. |
Methods
Constructs a ModuleHandler object.
Includes a module's .module file.
Loads all enabled modules.
Reloads all enabled modules.
Returns whether all modules have been loaded.
Returns the list of currently active modules.
Returns a module extension object from the currently active modules list.
Sets an explicit list of currently active modules.
Adds a module to the list of currently active modules.
Adds an installation profile to the list of currently active modules.
Adds a module or profile to the list of currently active modules.
Determines which modules require and are required by each module.
Determines whether a given module is enabled.
Loads an include file for each enabled module.
Loads a module include file.
Retrieves a list of hooks that are declared through hook_hook_info().
Builds hook_hook_info() information.
Determines which modules are implementing a hook.
Write the hook implementation info to the cache.
Resets the cached list of hook implementations.
Returns whether a given module implements a given hook.
Invokes a hook in a particular module.
Invokes a hook in all enabled modules that implement it.
Invokes a deprecated hook in a particular module.
Invokes a deprecated hook in all enabled modules that implement it.
Passes alterable variables to specific hook_TYPE_alter() implementations.
Passes alterable variables to deprecated hook_TYPE_alter() implementations.
Provides information about modules' implementations of a hook.
Builds hook implementation information for a given hook name.
Verifies an array of implementations loaded from the cache, by including the lazy-loaded $module.$group.inc, and checking function_exists().
Returns an array of directories for all enabled modules. Useful for tasks such as finding a file that exists in all module directories.
Gets the human readable name of a given module.
Details
__construct(string $root, array $module_list, CacheBackendInterface $cache_backend)
Constructs a ModuleHandler object.
bool
load(string $name)
Includes a module's .module file.
This prevents including a module more than once.
loadAll()
Loads all enabled modules.
reload()
Reloads all enabled modules.
bool
isLoaded()
Returns whether all modules have been loaded.
Extension[]
getModuleList()
Returns the list of currently active modules.
Extension
getModule(string $name)
Returns a module extension object from the currently active modules list.
setModuleList(array $module_list = [])
Sets an explicit list of currently active modules.
addModule(string $name, string $path)
Adds a module to the list of currently active modules.
addProfile(string $name, string $path)
Adds an installation profile to the list of currently active modules.
protected
add(string $type, string $name, string $path)
Adds a module or profile to the list of currently active modules.
The
buildModuleDependencies(array $modules)
Determines which modules require and are required by each module.
bool
moduleExists(string $module)
Determines whether a given module is enabled.
loadAllIncludes(string $type, string $name = NULL)
Loads an include file for each enabled module.
string|false
loadInclude(string $module, string $type, string $name = NULL)
Loads a module include file.
Examples:
array
getHookInfo()
Retrieves a list of hooks that are declared through hook_hook_info().
protected
buildHookInfo()
Builds hook_hook_info() information.
array
getImplementations(string $hook)
Determines which modules are implementing a hook.
writeCache()
Write the hook implementation info to the cache.
resetImplementations()
Resets the cached list of hook implementations.
bool
implementsHook(string $module, string $hook)
Returns whether a given module implements a given hook.
mixed
invoke(string $module, string $hook, array $args = [])
Invokes a hook in a particular module.
array
invokeAll(string $hook, array $args = [])
Invokes a hook in all enabled modules that implement it.
mixed
invokeDeprecated(string $description, string $module, string $hook, array $args = [])
Invokes a deprecated hook in a particular module.
Invoking a deprecated hook adds the behavior of triggering an E_USER_DEPRECATED error if any implementations are found.
API maintainers should use this method instead of invoke() when their hook is deprecated. This method does not detect when a hook is deprecated.
array
invokeAllDeprecated(string $description, string $hook, array $args = [])
Invokes a deprecated hook in all enabled modules that implement it.
Invoking a deprecated hook adds the behavior of triggering an E_USER_DEPRECATED error if any implementations are found.
API maintainers should use this method instead of invokeAll() when their hook is deprecated. This method does not detect when a hook is deprecated.
alter(string|array $type, mixed $data, mixed $context1 = NULL, mixed $context2 = NULL)
Passes alterable variables to specific hook_TYPE_alter() implementations.
This dispatch function hands off the passed-in variables to type-specific hook_TYPE_alter() implementations in modules. It ensures a consistent interface for all altering operations.
A maximum of 2 alterable arguments is supported. In case more arguments need to be passed and alterable, modules provide additional variables assigned by reference in the last $context argument:
alterDeprecated(string $description, string|array $type, mixed $data, mixed $context1 = NULL, mixed $context2 = NULL)
Passes alterable variables to deprecated hook_TYPE_alter() implementations.
This method triggers an E_USER_DEPRECATED error if any implementations of the alter hook are found. It is otherwise identical to alter().
See the documentation for alter() for more details.
protected array
getImplementationInfo(string $hook)
Provides information about modules' implementations of a hook.
protected array
buildImplementationInfo(string $hook)
Builds hook implementation information for a given hook name.
protected bool
verifyImplementations(string[] $implementations, string $hook)
Verifies an array of implementations loaded from the cache, by including the lazy-loaded $module.$group.inc, and checking function_exists().
array
getModuleDirectories()
Returns an array of directories for all enabled modules. Useful for tasks such as finding a file that exists in all module directories.
string
getName(string $module)
Gets the human readable name of a given module.