Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / lib / Drupal / Core / Extension / ModuleHandler.php
index cfbaa61a8e4129acb5818ab59df108943c6d9750..8d43a857dd4c7a678ad190456b2ed14dcfe0b74e 100644 (file)
@@ -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.
@@ -106,7 +107,7 @@ class ModuleHandler implements ModuleHandlerInterface {
    * @see \Drupal\Core\DrupalKernel
    * @see \Drupal\Core\CoreServiceProvider
    */
-  public function __construct($root, array $module_list = [], CacheBackendInterface $cache_backend) {
+  public function __construct($root, array $module_list, CacheBackendInterface $cache_backend) {
     $this->root = $root;
     $this->moduleList = [];
     foreach ($module_list as $name => $module) {
@@ -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);
   }
 
 }