Mercurial > hg > isophonics-drupal-site
comparison core/lib/Drupal/Core/Annotation/ContextDefinition.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 |
---|---|
114 } | 114 } |
115 } | 115 } |
116 if (isset($values['class']) && !in_array('Drupal\Core\Plugin\Context\ContextDefinitionInterface', class_implements($values['class']))) { | 116 if (isset($values['class']) && !in_array('Drupal\Core\Plugin\Context\ContextDefinitionInterface', class_implements($values['class']))) { |
117 throw new \Exception('ContextDefinition class must implement \Drupal\Core\Plugin\Context\ContextDefinitionInterface.'); | 117 throw new \Exception('ContextDefinition class must implement \Drupal\Core\Plugin\Context\ContextDefinitionInterface.'); |
118 } | 118 } |
119 $class = isset($values['class']) ? $values['class'] : 'Drupal\Core\Plugin\Context\ContextDefinition'; | 119 |
120 $class = $this->getDefinitionClass($values); | |
120 $this->definition = new $class($values['value'], $values['label'], $values['required'], $values['multiple'], $values['description'], $values['default_value']); | 121 $this->definition = new $class($values['value'], $values['label'], $values['required'], $values['multiple'], $values['description'], $values['default_value']); |
122 } | |
123 | |
124 /** | |
125 * Determines the context definition class to use. | |
126 * | |
127 * If the annotation specifies a specific context definition class, we use | |
128 * that. Otherwise, we use \Drupal\Core\Plugin\Context\EntityContextDefinition | |
129 * if the data type starts with 'entity:', since it contains specialized logic | |
130 * specific to entities. Otherwise, we fall back to the generic | |
131 * \Drupal\Core\Plugin\Context\ContextDefinition class. | |
132 * | |
133 * @param array $values | |
134 * The annotation values. | |
135 * | |
136 * @return string | |
137 * The fully-qualified name of the context definition class. | |
138 */ | |
139 protected function getDefinitionClass(array $values) { | |
140 if (isset($values['class'])) { | |
141 return $values['class']; | |
142 } | |
143 if (strpos($values['value'], 'entity:') === 0) { | |
144 return 'Drupal\Core\Plugin\Context\EntityContextDefinition'; | |
145 } | |
146 return 'Drupal\Core\Plugin\Context\ContextDefinition'; | |
121 } | 147 } |
122 | 148 |
123 /** | 149 /** |
124 * Returns the value of an annotation. | 150 * Returns the value of an annotation. |
125 * | 151 * |