W3cubDocs

/Drupal 8

protected function ModuleHandler::verifyImplementations

protected ModuleHandler::verifyImplementations(&$implementations, $hook)

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 $hook: The hook name.

Return value

bool TRUE, if all implementations exist. FALSE, if one or more implementations don't exist and need to be removed from the cache.

File

core/lib/Drupal/Core/Extension/ModuleHandler.php, line 612

Class

ModuleHandler
Class that manages modules in a Drupal installation.

Namespace

Drupal\Core\Extension

Code

protected function verifyImplementations(&$implementations, $hook) {
  $all_valid = TRUE;
  foreach ($implementations as $module => $group) {
    // If this hook implementation is stored in a lazy-loaded file, include
    // that file first.
    if ($group) {
      $this->loadInclude($module, 'inc', "$module.$group");
    }
    // It is possible that a module removed a hook implementation without
    // the implementations cache being rebuilt yet, so we check whether the
    // function exists on each request to avoid undefined function errors.
    // Since ModuleHandler::implementsHook() may needlessly try to
    // load the include file again, function_exists() is used directly here.
    if (!function_exists($module . '_' . $hook)) {
      // Clear out the stale implementation from the cache and force a cache
      // refresh to forget about no longer existing hook implementations.
      unset($implementations[$module]);
      // One of the implementations did not exist and needs to be removed in
      // the cache.
      $all_valid = FALSE;
    }
  }
  return $all_valid;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Extension!ModuleHandler.php/function/ModuleHandler::verifyImplementations/8.1.x