diff core/lib/Drupal/Core/Plugin/PluginDependencyTrait.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents a9cd425dd02b
children
line wrap: on
line diff
--- a/core/lib/Drupal/Core/Plugin/PluginDependencyTrait.php	Thu Feb 28 13:11:55 2019 +0000
+++ b/core/lib/Drupal/Core/Plugin/PluginDependencyTrait.php	Thu May 09 15:34:47 2019 +0100
@@ -33,20 +33,44 @@
   protected function getPluginDependencies(PluginInspectionInterface $instance) {
     $dependencies = [];
     $definition = $instance->getPluginDefinition();
+
+    $provider = NULL;
+    $config_dependencies = [];
     if ($definition instanceof PluginDefinitionInterface) {
-      $dependencies['module'][] = $definition->getProvider();
-      if ($definition instanceof DependentPluginDefinitionInterface && $config_dependencies = $definition->getConfigDependencies()) {
-        $dependencies = NestedArray::mergeDeep($dependencies, $config_dependencies);
+      $provider = $definition->getProvider();
+
+      if ($definition instanceof DependentPluginDefinitionInterface) {
+        $config_dependencies = $definition->getConfigDependencies();
       }
     }
     elseif (is_array($definition)) {
-      $dependencies['module'][] = $definition['provider'];
-      // Plugins can declare additional dependencies in their definition.
+      $provider = $definition['provider'];
+
       if (isset($definition['config_dependencies'])) {
-        $dependencies = NestedArray::mergeDeep($dependencies, $definition['config_dependencies']);
+        $config_dependencies = $definition['config_dependencies'];
       }
     }
 
+    // Add the provider as a dependency, taking into account if it's a module or
+    // a theme.
+    if ($provider) {
+      if ($provider === 'core' || $this->moduleHandler()->moduleExists($provider)) {
+        $dependencies['module'][] = $provider;
+      }
+      elseif ($this->themeHandler()->themeExists($provider)) {
+        $dependencies['theme'][] = $provider;
+      }
+      else {
+        @trigger_error('Declaring a dependency on an uninstalled module is deprecated in Drupal 8.7.0 and will not be supported in Drupal 9.0.0.', E_USER_DEPRECATED);
+        $dependencies['module'][] = $provider;
+      }
+    }
+
+    // Add the config dependencies.
+    if ($config_dependencies) {
+      $dependencies = NestedArray::mergeDeep($dependencies, $config_dependencies);
+    }
+
     // If a plugin is dependent, calculate its dependencies.
     if ($instance instanceof DependentPluginInterface && $plugin_dependencies = $instance->calculateDependencies()) {
       $dependencies = NestedArray::mergeDeep($dependencies, $plugin_dependencies);
@@ -69,4 +93,24 @@
     $this->addDependencies($this->getPluginDependencies($instance));
   }
 
+  /**
+   * Wraps the module handler.
+   *
+   * @return \Drupal\Core\Extension\ModuleHandlerInterface
+   *   The module handler.
+   */
+  protected function moduleHandler() {
+    return \Drupal::moduleHandler();
+  }
+
+  /**
+   * Wraps the theme handler.
+   *
+   * @return \Drupal\Core\Extension\ThemeHandlerInterface
+   *   The theme handler.
+   */
+  protected function themeHandler() {
+    return \Drupal::service('theme_handler');
+  }
+
 }