class EntityIsOfBundle
Provides an 'Entity is of bundle' condition.
@todo Add access callback information from Drupal 7?
Plugin annotation
@Condition(
id = "rules_entity_is_of_bundle",
label = @Translation("Entity is of bundle"),
category = @Translation("Entity"),
context_definitions = {
"entity" = @ContextDefinition("entity",
label = @Translation("Entity"),
description = @Translation("Specifies the entity for which to evaluate the condition."),
assignment_restriction = "selector"
),
"type" = @ContextDefinition("string",
label = @Translation("Type"),
description = @Translation("The type of the evaluated entity."),
options_provider = "\Drupal\rules\TypedData\Options\EntityTypeOptions",
assignment_restriction = "input"
),
"bundle" = @ContextDefinition("string",
label = @Translation("Bundle"),
description = @Translation("The bundle of the evaluated entity."),
options_provider = "\Drupal\rules\TypedData\Options\EntityBundleOptions",
assignment_restriction = "input"
),
}
)
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\rules\Core\RulesConditionBase extends \Drupal\Core\Condition\ConditionPluginBase implements \Drupal\rules\Core\RulesConditionInterface uses \Drupal\rules\Context\ContextProviderTrait, \Drupal\rules\Core\ExecutablePluginTrait, \Drupal\rules\Core\ConfigurationAccessControlTrait
- class \Drupal\rules\Plugin\Condition\EntityIsOfBundle extends \Drupal\rules\Core\RulesConditionBase
- class \Drupal\rules\Core\RulesConditionBase extends \Drupal\Core\Condition\ConditionPluginBase implements \Drupal\rules\Core\RulesConditionInterface uses \Drupal\rules\Context\ContextProviderTrait, \Drupal\rules\Core\ExecutablePluginTrait, \Drupal\rules\Core\ConfigurationAccessControlTrait
- 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 EntityIsOfBundle
File
-
src/
Plugin/ Condition/ EntityIsOfBundle.php, line 38
Namespace
Drupal\rules\Plugin\ConditionView source
class EntityIsOfBundle extends RulesConditionBase {
/**
* Check if a provided entity is of a specific type and bundle.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity to check the bundle and type of.
* @param string $type
* The type to check for.
* @param string $bundle
* The bundle to check for.
*
* @return bool
* TRUE if the provided entity is of the provided type and bundle.
*/
protected function doEvaluate(EntityInterface $entity, $type, $bundle) {
$entity_type = $entity->getEntityTypeId();
$entity_bundle = $entity->bundle();
// Check to see whether the entity's bundle and type match the specified
// values.
return $entity_bundle == $bundle && $entity_type == $type;
}
/**
* {@inheritdoc}
*/
public function assertMetadata(array $selected_data) {
// Assert the checked bundle.
$changed_definitions = [];
if (isset($selected_data['entity']) && ($bundle = $this->getContextValue('bundle'))) {
$changed_definitions['entity'] = clone $selected_data['entity'];
$bundles = is_array($bundle) ? $bundle : [
$bundle,
];
$changed_definitions['entity']->setBundles($bundles);
}
return $changed_definitions;
}
}