3 namespace Drupal\ctools\Plugin\Condition;
5 use Drupal\node\Plugin\Condition\NodeType as CoreNodeType;
6 use Drupal\ctools\ConstraintConditionInterface;
8 class NodeType extends CoreNodeType implements ConstraintConditionInterface {
13 * @param \Drupal\Core\Plugin\Context\ContextInterface[] $contexts
15 public function applyConstraints(array $contexts = array()) {
16 // Nullify any bundle constraints on contexts we care about.
17 $this->removeConstraints($contexts);
18 // If a single bundle is configured, we can set a proper constraint.
19 if (count($this->configuration['bundles']) == 1) {
20 $bundle = array_values($this->configuration['bundles']);
21 foreach ($this->getContextMapping() as $definition_id => $context_id) {
22 $contexts[$context_id]->getContextDefinition()->addConstraint('Bundle', ['value' => $bundle[0]]);
30 * @param \Drupal\Core\Plugin\Context\ContextInterface[] $contexts
32 public function removeConstraints(array $contexts = array()) {
33 // Reset the bundle constraint for any context we've mapped.
34 foreach ($this->getContextMapping() as $definition_id => $context_id) {
35 $constraints = $contexts[$context_id]->getContextDefinition()->getConstraints();
36 unset($constraints['Bundle']);
37 $contexts[$context_id]->getContextDefinition()->setConstraints($constraints);