X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fcore%2Flib%2FDrupal%2FCore%2FExtension%2FModuleHandler.php;fp=web%2Fcore%2Flib%2FDrupal%2FCore%2FExtension%2FModuleHandler.php;h=7d69c3cb82ba82b64a8f6bb757fcd9fbeec87595;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hp=d8d36088accd7254650809a05e03c7d7a129cbe7;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0;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..7d69c3cb8 100644 --- a/web/core/lib/Drupal/Core/Extension/ModuleHandler.php +++ b/web/core/lib/Drupal/Core/Extension/ModuleHandler.php @@ -411,6 +411,44 @@ 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. *