class EntityBundleConstraint
Entity Bundle Constraints
Adds constraints to Drupal\Core\Entity\Plugin\Condition\EntityBundle.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait
- class \Drupal\Core\Executable\ExecutablePluginBase extends \Drupal\Core\Plugin\PluginBase implements \Drupal\Core\Executable\ExecutableInterface, \Drupal\Core\Cache\CacheableDependencyInterface, \Drupal\Core\Plugin\ContextAwarePluginInterface uses \Drupal\Core\Plugin\ContextAwarePluginTrait
- class \Drupal\Core\Condition\ConditionPluginBase extends \Drupal\Core\Executable\ExecutablePluginBase implements \Drupal\Core\Condition\ConditionInterface uses \Drupal\Core\Plugin\ContextAwarePluginAssignmentTrait
- class \Drupal\Core\Entity\Plugin\Condition\EntityBundle extends \Drupal\Core\Condition\ConditionPluginBase implements \Drupal\Core\Plugin\ContainerFactoryPluginInterface
- class \Drupal\ctools\Plugin\Condition\EntityBundleConstraint extends \Drupal\Core\Entity\Plugin\Condition\EntityBundle implements \Drupal\ctools\ConstraintConditionInterface
- class \Drupal\Core\Entity\Plugin\Condition\EntityBundle extends \Drupal\Core\Condition\ConditionPluginBase implements \Drupal\Core\Plugin\ContainerFactoryPluginInterface
- class \Drupal\Core\Condition\ConditionPluginBase extends \Drupal\Core\Executable\ExecutablePluginBase implements \Drupal\Core\Condition\ConditionInterface uses \Drupal\Core\Plugin\ContextAwarePluginAssignmentTrait
- class \Drupal\Core\Executable\ExecutablePluginBase extends \Drupal\Core\Plugin\PluginBase implements \Drupal\Core\Executable\ExecutableInterface, \Drupal\Core\Cache\CacheableDependencyInterface, \Drupal\Core\Plugin\ContextAwarePluginInterface uses \Drupal\Core\Plugin\ContextAwarePluginTrait
- class \Drupal\Core\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait
Expanded class hierarchy of EntityBundleConstraint
1 file declares its use of EntityBundleConstraint
- ctools.module in ./
ctools.module - Provides utility and helper APIs for Drupal developers and site builders.
File
-
src/
Plugin/ Condition/ EntityBundleConstraint.php, line 13
Namespace
Drupal\ctools\Plugin\ConditionView source
class EntityBundleConstraint extends CoreEntityBundle 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);
$bundle = array_values($this->configuration['bundles']);
// There's only one expected context for this plugin type.
foreach ($this->getContextMapping() as $definition_id => $context_id) {
$contexts[$context_id]->getContextDefinition()
->addConstraint('Bundle', [
'value' => $bundle,
]);
}
}
/**
* {@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);
}
}
}