Drupal 8  8.0.2
ModuleHandler Class Reference
Inheritance diagram for ModuleHandler:

Public Member Functions

 __construct ($root, array $module_list=array(), CacheBackendInterface $cache_backend)
 
 load ($name)
 
 loadAll ()
 
 reload ()
 
 isLoaded ()
 
 getModuleList ()
 
 getModule ($name)
 
 setModuleList (array $module_list=array())
 
 addModule ($name, $path)
 
 addProfile ($name, $path)
 
 buildModuleDependencies (array $modules)
 
 moduleExists ($module)
 
 loadAllIncludes ($type, $name=NULL)
 
 loadInclude ($module, $type, $name=NULL)
 
 getHookInfo ()
 
 getImplementations ($hook)
 
 writeCache ()
 
 resetImplementations ()
 
 implementsHook ($module, $hook)
 
 invoke ($module, $hook, array $args=array())
 
 invokeAll ($hook, array $args=array())
 
 alter ($type, &$data, &$context1=NULL, &$context2=NULL)
 
 getModuleDirectories ()
 
 getName ($module)
 

Static Public Member Functions

static parseDependency ($dependency)
 

Protected Member Functions

 add ($type, $name, $path)
 
 buildHookInfo ()
 
 getImplementationInfo ($hook)
 
 buildImplementationInfo ($hook)
 
 verifyImplementations (&$implementations, $hook)
 

Protected Attributes

 $loadedFiles
 
 $moduleList
 
 $loaded = FALSE
 
 $implementations
 
 $verified
 
 $hookInfo
 
 $cacheBackend
 
 $cacheNeedsWriting = FALSE
 
 $alterFunctions
 
 $root
 

Detailed Description

Class that manages modules in a Drupal installation.

Constructor & Destructor Documentation

__construct (   $root,
array  $module_list = array(),
CacheBackendInterface  $cache_backend 
)

Constructs a ModuleHandler object.

Parameters
string$rootThe app root.
array$module_listAn associative array whose keys are the names of installed modules and whose values are Extension class parameters. This is normally the container.modules% parameter being set up by DrupalKernel.
\Drupal\Core\Cache\CacheBackendInterface$cache_backendCache backend for storing module hook implementation information.
See Also

References Drupal\root().

Here is the call graph for this function:

Member Function Documentation

add (   $type,
  $name,
  $path 
)
protected

Adds a module or profile to the list of currently active modules.

Parameters
string$typeThe extension type; either 'module' or 'profile'.
string$nameThe module name; e.g., 'node'.
string$pathThe module path; e.g., 'core/modules/node'.

References ModuleHandler\resetImplementations(), and Drupal\root().

Referenced by ModuleHandler\addModule(), and ModuleHandler\addProfile().

Here is the call graph for this function:

Here is the caller graph for this function:

addModule (   $name,
  $path 
)

{Adds a module to the list of currently active modules.

Parameters
string$nameThe module name; e.g., 'node'.
string$pathThe module path; e.g., 'core/modules/node'.
}

Implements ModuleHandlerInterface.

References ModuleHandler\add().

Here is the call graph for this function:

addProfile (   $name,
  $path 
)

{Adds an installation profile to the list of currently active modules.

Parameters
string$nameThe profile name; e.g., 'standard'.
string$pathThe profile path; e.g., 'core/profiles/standard'.
}

Implements ModuleHandlerInterface.

References ModuleHandler\add().

Here is the call graph for this function:

alter (   $type,
$data,
$context1 = NULL,
$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:

$context = array(
'alterable' => &$alterable,
'unalterable' => $unalterable,
'foo' => 'bar',
);
$this->alter('mymodule_data', $alterable1, $alterable2, $context);
Note that objects are always passed by reference in PHP5. If it is absolutely required that no implementation alters a passed object in $context, then an object needs to be cloned:

$context = array(
'unalterable_object' => clone $object,
);
$this->alter('mymodule_data', $data, $context);
Parameters
string | array$typeA string describing the type of the alterable $data. 'form', 'links', 'node_content', and so on are several examples. Alternatively can be an array, in which case hook_TYPE_alter() is invoked for each value in the array, ordered first by module, and then for each module, in the order of values in $type. For example, when Form API is using $this->alter() to execute both hook_form_alter() and hook_form_FORM_ID_alter() implementations, it passes array('form', 'form_' . $form_id) for $type.
mixed$dataThe variable that will be passed to hook_TYPE_alter() implementations to be altered. The type of this variable depends on the value of the $type argument. For example, when altering a 'form', $data will be a structured array. When altering a 'profile', $data will be an object.
mixed$context1(optional) An additional variable that is passed by reference.
mixed$context2(optional) An additional variable that is passed by reference. If more context needs to be provided to implementations, then this should be an associative array as described above.
}

Implements ModuleHandlerInterface.

References ModuleHandler\getImplementations().

Referenced by ModuleHandler\buildImplementationInfo().

Here is the call graph for this function:

Here is the caller graph for this function:

buildHookInfo ( )
protected

Builds hook_hook_info() information.

See Also
::getHookInfo()

References NestedArray\mergeDeep(), and ModuleHandler\reload().

Referenced by ModuleHandler\getHookInfo().

Here is the call graph for this function:

Here is the caller graph for this function:

buildImplementationInfo (   $hook)
protected

Builds hook implementation information for a given hook name.

Parameters
string$hookThe name of the hook (e.g. "help" or "menu").
Returns
mixed[] An array whose keys are the names of the modules which are implementing this hook and whose values are either a string identifying a file in which the implementation is to be found, or FALSE, if the implementation is in the module file.
Exceptions
\RuntimeExceptionException thrown when an invalid implementation is added by hook_module_implements_alter().
See Also
::getImplementationInfo()

References ModuleHandler\alter(), ModuleHandler\getHookInfo(), and ModuleHandler\loadInclude().

Referenced by ModuleHandler\getImplementationInfo().

Here is the call graph for this function:

Here is the caller graph for this function:

buildModuleDependencies ( array  $modules)

{Determines which modules require and are required by each module.

Parameters
array$modulesAn array of module objects keyed by module name. Each object contains information discovered during a Drupal scan.
Returns
The same array with the new keys for each module:
  • requires: An array with the keys being the modules that this module requires.
  • required_by: An array with the keys being the modules that will not work without this module.
See Also
}

Implements ModuleHandlerInterface.

getHookInfo ( )

{Retrieves a list of hooks that are declared through hook_hook_info().

Returns
array An associative array whose keys are hook names and whose values are an associative array containing a group name. The structure of the array is the same as the return value of hook_hook_info().
See Also
hook_hook_info()
}

Implements ModuleHandlerInterface.

References ModuleHandler\buildHookInfo().

Referenced by ModuleHandler\buildImplementationInfo(), and ModuleHandler\implementsHook().

Here is the call graph for this function:

Here is the caller graph for this function:

getImplementationInfo (   $hook)
protected

Provides information about modules' implementations of a hook.

Parameters
string$hookThe name of the hook (e.g. "help" or "menu").
Returns
mixed[] An array whose keys are the names of the modules which are implementing this hook and whose values are either a string identifying a file in which the implementation is to be found, or FALSE, if the implementation is in the module file.

References ModuleHandler\buildImplementationInfo(), and ModuleHandler\verifyImplementations().

Referenced by ModuleHandler\getImplementations().

Here is the call graph for this function:

Here is the caller graph for this function:

getImplementations (   $hook)

{Determines which modules are implementing a hook.

Parameters
string$hookThe name of the hook (e.g. "help" or "menu").
Returns
array An array with the names of the modules which are implementing this hook.
}

Implements ModuleHandlerInterface.

References ModuleHandler\getImplementationInfo().

Referenced by ModuleHandler\alter(), and ModuleHandler\invokeAll().

Here is the call graph for this function:

Here is the caller graph for this function:

getModule (   $name)

{Returns a module extension object from the currently active modules list.

Parameters
string$nameThe name of the module to return.
Returns
An extension object.
Exceptions
\InvalidArgumentExceptionThrown when the requested module does not exist.
}

Implements ModuleHandlerInterface.

getModuleDirectories ( )

{Returns an array of directories for all enabled modules. Useful for tasks such as finding a file that exists in all module directories.

Returns
array
}

Implements ModuleHandlerInterface.

References ModuleHandler\getModuleList(), and Drupal\root().

Here is the call graph for this function:

getModuleList ( )

{Returns the list of currently active modules.

Returns
[] An associative array whose keys are the names of the modules and whose values are Extension objects.
}

Implements ModuleHandlerInterface.

Referenced by ModuleHandler\getModuleDirectories().

Here is the caller graph for this function:

getName (   $module)

{Gets the human readable name of a given module.

Parameters
string$moduleThe machine name of the module which title should be shown.
Returns
string Returns the human readable name of the module or the machine name passed in if no matching module is found.
}

Implements ModuleHandlerInterface.

implementsHook (   $module,
  $hook 
)

{Returns whether a given module implements a given hook.

Parameters
string$moduleThe name of the module (without the .module extension).
string$hookThe name of the hook (e.g. "help" or "menu").
Returns
bool TRUE if the module is both installed and enabled, and the hook is implemented in that module.
}

Implements ModuleHandlerInterface.

References ModuleHandler\getHookInfo(), and ModuleHandler\loadInclude().

Referenced by ModuleHandler\invoke().

Here is the call graph for this function:

Here is the caller graph for this function:

invoke (   $module,
  $hook,
array  $args = array() 
)

{Invokes a hook in a particular module.

Parameters
string$moduleThe name of the module (without the .module extension).
string$hookThe name of the hook to invoke.
...Arguments to pass to the hook implementation.
Returns
mixed The return value of the hook implementation.
}

Implements ModuleHandlerInterface.

References ModuleHandler\implementsHook().

Here is the call graph for this function:

invokeAll (   $hook,
array  $args = array() 
)

{Invokes a hook in all enabled modules that implement it.

Parameters
string$hookThe name of the hook to invoke.
array$argsArguments to pass to the hook.
Returns
array An array of return values of the hook implementations. If modules return arrays from their implementations, those are merged into one array.
}

Implements ModuleHandlerInterface.

References ModuleHandler\getImplementations(), and NestedArray\mergeDeep().

Here is the call graph for this function:

isLoaded ( )

{Returns whether all modules have been loaded.

Returns
bool A Boolean indicating whether all modules have been loaded. This means all modules; the load status of bootstrap modules cannot be checked.
}

Implements ModuleHandlerInterface.

load (   $name)

{Includes a module's .module file.This prevents including a module more than once.

Parameters
string$nameThe name of the module to load.
Returns
bool TRUE if the item is loaded or has already been loaded.
}

Implements ModuleHandlerInterface.

Referenced by ModuleHandler\loadAll().

Here is the caller graph for this function:

loadAll ( )

{Loads all enabled modules.}

Implements ModuleHandlerInterface.

References ModuleHandler\load().

Referenced by ModuleHandler\reload().

Here is the call graph for this function:

Here is the caller graph for this function:

loadAllIncludes (   $type,
  $name = NULL 
)

{Loads an include file for each enabled module.

Parameters
string$typeThe include file's type (file extension).
string$name(optional) The base file name (without the $type extension). If omitted, each module's name is used; i.e., "$module.$type" by default.
}

Implements ModuleHandlerInterface.

References ModuleHandler\loadInclude().

Here is the call graph for this function:

loadInclude (   $module,
  $type,
  $name = NULL 
)

{Loads a module include file.Examples:

// Load node.admin.inc from the node module.
$this->loadInclude('node', 'inc', 'node.admin');
// Load content_types.inc from the node module.
$this->loadInclude('node', 'inc', ''content_types');
Parameters
string$moduleThe module to which the include file belongs.
string$typeThe include file's type (file extension).
string$name(optional) The base file name (without the $type extension). If omitted, $module is used; i.e., resulting in "$module.$type" by default.
Returns
string|false The name of the included file, if successful; FALSE otherwise.
}

Implements ModuleHandlerInterface.

References Drupal\root().

Referenced by ModuleHandler\buildImplementationInfo(), ModuleHandler\implementsHook(), ModuleHandler\loadAllIncludes(), and ModuleHandler\verifyImplementations().

Here is the call graph for this function:

Here is the caller graph for this function:

moduleExists (   $module)

{Determines whether a given module is enabled.

Parameters
string$moduleThe name of the module (without the .module extension).
Returns
bool TRUE if the module is both installed and enabled.
}

Implements ModuleHandlerInterface.

static parseDependency (   $dependency)
static

Parses a dependency for comparison by drupal_check_incompatibility().

Parameters
$dependencyA dependency string, which specifies a module dependency, and optionally the project it comes from and versions that are supported. Supported formats include:
  • 'module'
  • 'project:module'
  • 'project:module (>=version, version)'
Returns
An associative array with three keys:
  • 'name' includes the name of the thing to depend on (e.g. 'foo').
  • 'original_version' contains the original version string (which can be used in the UI for reporting incompatibilities).
  • 'versions' is a list of associative arrays, each containing the keys 'op' and 'version'. 'op' can be one of: '=', '==', '!=', '<>', '<', '<=', '>', or '>='. 'version' is one piece like '4.5-beta3'. Callers should pass this structure to drupal_check_incompatibility().
See Also
drupal_check_incompatibility()

References Drupal\CORE_COMPATIBILITY.

Referenced by ModuleHandlerTest\testDependencyParsing().

Here is the caller graph for this function:

reload ( )

{Reloads all enabled modules.}

Implements ModuleHandlerInterface.

References ModuleHandler\loadAll().

Referenced by ModuleHandler\buildHookInfo().

Here is the call graph for this function:

Here is the caller graph for this function:

resetImplementations ( )

{Resets the cached list of hook implementations.}

Implements ModuleHandlerInterface.

Referenced by ModuleHandler\add(), and ModuleHandler\setModuleList().

Here is the caller graph for this function:

setModuleList ( array  $module_list = array())

{Sets an explicit list of currently active modules.

Parameters
\Drupal\Core\Extension\Extension[]$module_list An associative array whose keys are the names of the modules and whose values are Extension objects.
}

Implements ModuleHandlerInterface.

References ModuleHandler\resetImplementations().

Here is the call graph for this function:

verifyImplementations ( $implementations,
  $hook 
)
protected

Verifies an array of implementations loaded from the cache, by including the lazy-loaded $module.$group.inc, and checking function_exists().

Parameters
string[]$implementations Implementation "group" by module name.
string$hookThe hook name.
Returns
bool TRUE, if all implementations exist. FALSE, if one or more implementations don't exist and need to be removed from the cache.

References ModuleHandler\loadInclude().

Referenced by ModuleHandler\getImplementationInfo().

Here is the call graph for this function:

Here is the caller graph for this function:

writeCache ( )

{Write the hook implementation info to the cache.}

Implements ModuleHandlerInterface.


The documentation for this class was generated from the following file: