Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / lib / Drupal / Core / Extension / ModuleHandler.php
index d8d36088accd7254650809a05e03c7d7a129cbe7..7d69c3cb82ba82b64a8f6bb757fcd9fbeec87595 100644 (file)
@@ -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.
    *