comparison core/lib/Drupal/Core/Plugin/DefaultPluginManager.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents c75dbcec494b
children
comparison
equal deleted inserted replaced
4:a9cd425dd02b 5:12f9dff5fda9
284 $definitions = $this->getDiscovery()->getDefinitions(); 284 $definitions = $this->getDiscovery()->getDefinitions();
285 foreach ($definitions as $plugin_id => &$definition) { 285 foreach ($definitions as $plugin_id => &$definition) {
286 $this->processDefinition($definition, $plugin_id); 286 $this->processDefinition($definition, $plugin_id);
287 } 287 }
288 $this->alterDefinitions($definitions); 288 $this->alterDefinitions($definitions);
289 $this->fixContextAwareDefinitions($definitions);
289 // If this plugin was provided by a module that does not exist, remove the 290 // If this plugin was provided by a module that does not exist, remove the
290 // plugin definition. 291 // plugin definition.
291 foreach ($definitions as $plugin_id => $plugin_definition) { 292 foreach ($definitions as $plugin_id => $plugin_definition) {
292 $provider = $this->extractProviderFromDefinition($plugin_definition); 293 $provider = $this->extractProviderFromDefinition($plugin_definition);
293 if ($provider && !in_array($provider, ['core', 'component']) && !$this->providerExists($provider)) { 294 if ($provider && !in_array($provider, ['core', 'component']) && !$this->providerExists($provider)) {
296 } 297 }
297 return $definitions; 298 return $definitions;
298 } 299 }
299 300
300 /** 301 /**
302 * Fix the definitions of context-aware plugins.
303 *
304 * @param array $definitions
305 * The array of plugin definitions.
306 *
307 * @todo Remove before Drupal 9.0.0.
308 */
309 private function fixContextAwareDefinitions(array &$definitions) {
310 foreach ($definitions as $name => &$definition) {
311 if (is_array($definition) && (!empty($definition['context']) || !empty($definition['context_definitions']))) {
312 // Ensure the new definition key is available.
313 if (!isset($definition['context_definitions'])) {
314 $definition['context_definitions'] = [];
315 }
316
317 // If a context definition is defined with the old key, add it to the
318 // new key and trigger a deprecation error.
319 if (!empty($definition['context'])) {
320 $definition['context_definitions'] += $definition['context'];
321 @trigger_error('Providing context definitions via the "context" key is deprecated in Drupal 8.7.x and will be removed before Drupal 9.0.0. Use the "context_definitions" key instead.', E_USER_DEPRECATED);
322 }
323
324 // Copy the context definitions from the new key to the old key for
325 // backwards compatibility.
326 if (isset($definition['context'])) {
327 $definition['context'] = $definition['context_definitions'];
328 }
329 }
330 }
331 }
332
333 /**
301 * Extracts the provider from a plugin definition. 334 * Extracts the provider from a plugin definition.
302 * 335 *
303 * @param mixed $plugin_definition 336 * @param mixed $plugin_definition
304 * The plugin definition. Usually either an array or an instance of 337 * The plugin definition. Usually either an array or an instance of
305 * \Drupal\Component\Plugin\Definition\PluginDefinitionInterface 338 * \Drupal\Component\Plugin\Definition\PluginDefinitionInterface