class NodeType
Same name in other branches
- 8.x-3.x src/Plugin/Condition/NodeType.php \Drupal\ctools\Plugin\Condition\NodeType
Hierarchy
- class \Drupal\ctools\Plugin\Condition\NodeType extends \Drupal\node\Plugin\Condition\NodeType implements \Drupal\ctools\ConstraintConditionInterface
Expanded class hierarchy of NodeType
File
-
src/
Plugin/ Condition/ NodeType.php, line 19
Namespace
Drupal\ctools\Plugin\ConditionView source
class NodeType extends CoreNodeType implements ConstraintConditionInterface {
/**
* {@inheritdoc}
*
* @param \Drupal\Core\Plugin\Context\ContextInterface[] $contexts
*/
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],
]);
}
}
}
/**
* {@inheritdoc}
*
* @param \Drupal\Core\Plugin\Context\ContextInterface[] $contexts
*/
public function removeConstraints(array $contexts = []) {
// Reset the bundle constraint for any context we've mapped.
foreach ($this->getContextMapping() as $definition_id => $context_id) {
$constraints = $contexts[$context_id]->getContextDefinition()
->getConstraints();
unset($constraints['Bundle']);
$contexts[$context_id]->getContextDefinition()
->setConstraints($constraints);
}
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
NodeType::applyConstraints | public | function | Overrides ConstraintConditionInterface::applyConstraints | |
NodeType::removeConstraints | public | function | Overrides ConstraintConditionInterface::removeConstraints |