X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Flib%2FDrupal%2FCore%2FExtension%2FModuleHandler.php;h=8d43a857dd4c7a678ad190456b2ed14dcfe0b74e;hb=refs%2Fheads%2Fd864;hp=d8d36088accd7254650809a05e03c7d7a129cbe7;hpb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;p=yaffs-website diff --git a/web/core/lib/Drupal/Core/Extension/ModuleHandler.php b/web/core/lib/Drupal/Core/Extension/ModuleHandler.php index d8d36088a..8d43a857d 100644 --- a/web/core/lib/Drupal/Core/Extension/ModuleHandler.php +++ b/web/core/lib/Drupal/Core/Extension/ModuleHandler.php @@ -5,6 +5,7 @@ namespace Drupal\Core\Extension; use Drupal\Component\Graph\Graph; use Drupal\Component\Utility\NestedArray; use Drupal\Core\Cache\CacheBackendInterface; +use Drupal\Core\Extension\Exception\UnknownExtensionException; /** * Class that manages modules in a Drupal installation. @@ -172,7 +173,7 @@ class ModuleHandler implements ModuleHandlerInterface { if (isset($this->moduleList[$name])) { return $this->moduleList[$name]; } - throw new \InvalidArgumentException(sprintf('The module %s does not exist.', $name)); + throw new UnknownExtensionException(sprintf('The module %s does not exist.', $name)); } /** @@ -411,6 +412,43 @@ class ModuleHandler implements ModuleHandlerInterface { return $return; } + /** + * {@inheritdoc} + */ + public function invokeDeprecated($description, $module, $hook, array $args = []) { + $result = $this->invoke($module, $hook, $args); + $this->triggerDeprecationError($description, $hook); + return $result; + } + + /** + * {@inheritdoc} + */ + public function invokeAllDeprecated($description, $hook, array $args = []) { + $result = $this->invokeAll($hook, $args); + $this->triggerDeprecationError($description, $hook); + return $result; + } + + /** + * Triggers an E_USER_DEPRECATED error if any module implements the hook. + * + * @param string $description + * Helpful text describing what to do instead of implementing this hook. + * @param string $hook + * The name of the hook. + */ + private function triggerDeprecationError($description, $hook) { + $modules = array_keys($this->getImplementationInfo($hook)); + if (!empty($modules)) { + $message = 'The deprecated hook hook_' . $hook . '() is implemented in these functions: '; + $implementations = array_map(function ($module) use ($hook) { + return $module . '_' . $hook . '()'; + }, $modules); + @trigger_error($message . implode(', ', $implementations) . '. ' . $description, E_USER_DEPRECATED); + } + } + /** * {@inheritdoc} */ @@ -502,6 +540,28 @@ class ModuleHandler implements ModuleHandlerInterface { } } + /** + * {@inheritdoc} + */ + public function alterDeprecated($description, $type, &$data, &$context1 = NULL, &$context2 = NULL) { + // Invoke the alter hook. This has the side effect of populating + // $this->alterFunctions. + $this->alter($type, $data, $context1, $context2); + // The $type parameter can be an array. alter() will deal with this + // internally, but we have to extract the proper $cid in order to discover + // implementations. + $cid = $type; + if (is_array($type)) { + $cid = implode(',', $type); + $extra_types = $type; + $type = array_shift($extra_types); + } + if (!empty($this->alterFunctions[$cid])) { + $message = 'The deprecated alter hook hook_' . $type . '_alter() is implemented in these functions: ' . implode(', ', $this->alterFunctions[$cid]) . '.'; + @trigger_error($message . ' ' . $description, E_USER_DEPRECATED); + } + } + /** * Provides information about modules' implementations of a hook. * @@ -717,8 +777,7 @@ class ModuleHandler implements ModuleHandlerInterface { * {@inheritdoc} */ public function getName($module) { - $info = system_get_info('module', $module); - return isset($info['name']) ? $info['name'] : $module; + return \Drupal::service('extension.list.module')->getName($module); } }