Mercurial > hg > isophonics-drupal-site
comparison core/lib/Drupal/Component/Plugin/ContextAwarePluginBase.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 4c8ae668cc8c |
children | af1871eacc83 |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
1 <?php | 1 <?php |
2 | 2 |
3 namespace Drupal\Component\Plugin; | 3 namespace Drupal\Component\Plugin; |
4 | 4 |
5 use Drupal\Component\Plugin\Context\ContextInterface; | 5 use Drupal\Component\Plugin\Context\ContextInterface; |
6 use Drupal\Component\Plugin\Definition\ContextAwarePluginDefinitionInterface; | |
6 use Drupal\Component\Plugin\Exception\ContextException; | 7 use Drupal\Component\Plugin\Exception\ContextException; |
7 use Drupal\Component\Plugin\Context\Context; | 8 use Drupal\Component\Plugin\Context\Context; |
8 use Symfony\Component\Validator\ConstraintViolationList; | 9 use Symfony\Component\Validator\ConstraintViolationList; |
9 | 10 |
10 /** | 11 /** |
65 /** | 66 /** |
66 * {@inheritdoc} | 67 * {@inheritdoc} |
67 */ | 68 */ |
68 public function getContextDefinitions() { | 69 public function getContextDefinitions() { |
69 $definition = $this->getPluginDefinition(); | 70 $definition = $this->getPluginDefinition(); |
70 return !empty($definition['context']) ? $definition['context'] : []; | 71 if ($definition instanceof ContextAwarePluginDefinitionInterface) { |
72 return $definition->getContextDefinitions(); | |
73 } | |
74 else { | |
75 return !empty($definition['context']) ? $definition['context'] : []; | |
76 } | |
71 } | 77 } |
72 | 78 |
73 /** | 79 /** |
74 * {@inheritdoc} | 80 * {@inheritdoc} |
75 */ | 81 */ |
76 public function getContextDefinition($name) { | 82 public function getContextDefinition($name) { |
77 $definition = $this->getPluginDefinition(); | 83 $definition = $this->getPluginDefinition(); |
78 if (empty($definition['context'][$name])) { | 84 if ($definition instanceof ContextAwarePluginDefinitionInterface) { |
79 throw new ContextException(sprintf("The %s context is not a valid context.", $name)); | 85 if ($definition->hasContextDefinition($name)) { |
86 return $definition->getContextDefinition($name); | |
87 } | |
80 } | 88 } |
81 return $definition['context'][$name]; | 89 elseif (!empty($definition['context'][$name])) { |
90 return $definition['context'][$name]; | |
91 } | |
92 throw new ContextException(sprintf("The %s context is not a valid context.", $name)); | |
82 } | 93 } |
83 | 94 |
84 /** | 95 /** |
85 * {@inheritdoc} | 96 * {@inheritdoc} |
86 */ | 97 */ |