Providing Context to Rules Plugins
To provide context to a Rules Plugin, for example an entity for the entity delete action plugin, use the following format:
* context = {
* "entity" = @ContextDefinition("entity",
* label = @Translation("Entity"),
* description = @Translation("Specifies the entity, which should be deleted permanently.")
* )
* }
For example:
/**
* Provides a 'Delete entity' action.
*
* @Action(
* id = "rules_entity_delete",
* label = @Translation("Delete entity"),
* category = @Translation("Entity"),
* context = {
* "entity" = @ContextDefinition("entity",
* label = @Translation("Entity"),
* description = @Translation("Specifies the entity, which should be deleted permanently.")
* )
* }
* )
*/
class EntityDelete extends RulesActionBase {
/**
* {@inheritdoc}
*/
public function execute() {
$entity = $this->getContextValue('entity');
$entity->delete();
}
}