You are here

public function NodeType::applyConstraints in Chaos Tool Suite (ctools) 8.3

Parameters

\Drupal\Core\Plugin\Context\ContextInterface[] $contexts:

Overrides ConstraintConditionInterface::applyConstraints

File

src/Plugin/Condition/NodeType.php, line 16

Class

NodeType

Namespace

Drupal\ctools\Plugin\Condition

Code

public function applyConstraints(array $contexts = []) {

  // Nullify any bundle constraints on contexts we care about.
  $this
    ->removeConstraints($contexts);

  // If a single bundle is configured, we can set a proper constraint.
  if (count($this->configuration['bundles']) == 1) {
    $bundle = array_values($this->configuration['bundles']);
    foreach ($this
      ->getContextMapping() as $definition_id => $context_id) {
      $contexts[$context_id]
        ->getContextDefinition()
        ->addConstraint('Bundle', [
        'value' => $bundle[0],
      ]);
    }
  }
}