Mercurial > hg > cmmr2012-drupal-site
comparison 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 |
comparison
equal
deleted
inserted
replaced
4:a9cd425dd02b | 5:12f9dff5fda9 |
---|---|
31 * An array of dependencies keyed by the type of dependency. | 31 * An array of dependencies keyed by the type of dependency. |
32 */ | 32 */ |
33 protected function getPluginDependencies(PluginInspectionInterface $instance) { | 33 protected function getPluginDependencies(PluginInspectionInterface $instance) { |
34 $dependencies = []; | 34 $dependencies = []; |
35 $definition = $instance->getPluginDefinition(); | 35 $definition = $instance->getPluginDefinition(); |
36 | |
37 $provider = NULL; | |
38 $config_dependencies = []; | |
36 if ($definition instanceof PluginDefinitionInterface) { | 39 if ($definition instanceof PluginDefinitionInterface) { |
37 $dependencies['module'][] = $definition->getProvider(); | 40 $provider = $definition->getProvider(); |
38 if ($definition instanceof DependentPluginDefinitionInterface && $config_dependencies = $definition->getConfigDependencies()) { | 41 |
39 $dependencies = NestedArray::mergeDeep($dependencies, $config_dependencies); | 42 if ($definition instanceof DependentPluginDefinitionInterface) { |
43 $config_dependencies = $definition->getConfigDependencies(); | |
40 } | 44 } |
41 } | 45 } |
42 elseif (is_array($definition)) { | 46 elseif (is_array($definition)) { |
43 $dependencies['module'][] = $definition['provider']; | 47 $provider = $definition['provider']; |
44 // Plugins can declare additional dependencies in their definition. | 48 |
45 if (isset($definition['config_dependencies'])) { | 49 if (isset($definition['config_dependencies'])) { |
46 $dependencies = NestedArray::mergeDeep($dependencies, $definition['config_dependencies']); | 50 $config_dependencies = $definition['config_dependencies']; |
47 } | 51 } |
52 } | |
53 | |
54 // Add the provider as a dependency, taking into account if it's a module or | |
55 // a theme. | |
56 if ($provider) { | |
57 if ($provider === 'core' || $this->moduleHandler()->moduleExists($provider)) { | |
58 $dependencies['module'][] = $provider; | |
59 } | |
60 elseif ($this->themeHandler()->themeExists($provider)) { | |
61 $dependencies['theme'][] = $provider; | |
62 } | |
63 else { | |
64 @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); | |
65 $dependencies['module'][] = $provider; | |
66 } | |
67 } | |
68 | |
69 // Add the config dependencies. | |
70 if ($config_dependencies) { | |
71 $dependencies = NestedArray::mergeDeep($dependencies, $config_dependencies); | |
48 } | 72 } |
49 | 73 |
50 // If a plugin is dependent, calculate its dependencies. | 74 // If a plugin is dependent, calculate its dependencies. |
51 if ($instance instanceof DependentPluginInterface && $plugin_dependencies = $instance->calculateDependencies()) { | 75 if ($instance instanceof DependentPluginInterface && $plugin_dependencies = $instance->calculateDependencies()) { |
52 $dependencies = NestedArray::mergeDeep($dependencies, $plugin_dependencies); | 76 $dependencies = NestedArray::mergeDeep($dependencies, $plugin_dependencies); |
67 */ | 91 */ |
68 protected function calculatePluginDependencies(PluginInspectionInterface $instance) { | 92 protected function calculatePluginDependencies(PluginInspectionInterface $instance) { |
69 $this->addDependencies($this->getPluginDependencies($instance)); | 93 $this->addDependencies($this->getPluginDependencies($instance)); |
70 } | 94 } |
71 | 95 |
96 /** | |
97 * Wraps the module handler. | |
98 * | |
99 * @return \Drupal\Core\Extension\ModuleHandlerInterface | |
100 * The module handler. | |
101 */ | |
102 protected function moduleHandler() { | |
103 return \Drupal::moduleHandler(); | |
104 } | |
105 | |
106 /** | |
107 * Wraps the theme handler. | |
108 * | |
109 * @return \Drupal\Core\Extension\ThemeHandlerInterface | |
110 * The theme handler. | |
111 */ | |
112 protected function themeHandler() { | |
113 return \Drupal::service('theme_handler'); | |
114 } | |
115 | |
72 } | 116 } |