NodeType.php in Chaos Tool Suite (ctools) 8.3
File
src/Plugin/Condition/NodeType.php
View source
<?php
namespace Drupal\ctools\Plugin\Condition;
use Drupal\node\Plugin\Condition\NodeType as CoreNodeType;
use Drupal\ctools\ConstraintConditionInterface;
class NodeType extends CoreNodeType implements ConstraintConditionInterface {
public function applyConstraints(array $contexts = []) {
$this
->removeConstraints($contexts);
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],
]);
}
}
}
public function removeConstraints(array $contexts = []) {
foreach ($this
->getContextMapping() as $definition_id => $context_id) {
$constraints = $contexts[$context_id]
->getContextDefinition()
->getConstraints();
unset($constraints['Bundle']);
$contexts[$context_id]
->getContextDefinition()
->setConstraints($constraints);
}
}
}