I'm trying to write a custom RulesAction to perform an operation after an order status is updated. Basically, I want to perform this operation after checkout is complete (but this event doesn't exist anymore in D8).
namespace Drupal\my_module\Plugin\RulesAction;
use Drupal\uc_order\OrderInterface;
use Drupal\uc_order\OrderStatusInterface;
use Drupal\rules\Core\RulesActionBase;
/**
* Definition of the action performed.
*
* @RulesAction(
* id = "my_action_id",
* label = @Translation("My action label"),
* category = @Translation("My module"),
* context = {
* "entity" = @ContextDefinition("entity",
* label = @Translation("Entity"),
* description = @Translation("Specifies the entity, which should be saved permanently.")
* )
* }
* )
*/
class MyActionClass extends RulesActionBase {
/**
* Def.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The order update triggered by rules.
*/
protected function doExecute(OrderInterface $order) {
// @TODO.
}
}
My action do come in rules, I have set it up after the event: After updating order (rules_entity_update:uc_order)
When triggering it I get the error : If I set the context to entity (I've looked and no context is defined by ubercart for order):
The website encountered an unexpected error. Please try again later.Drupal\Core\Entity\EntityStorageException: Required context entity is missing for plugin my_action_id. in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 783 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).
If no context is set :
The website encountered an unexpected error. Please try again later. TypeError: Argument 1 passed to Drupal\my_module\Plugin\RulesAction\MyActionClass::doExecute() must implement interface Drupal\uc_order\OrderInterface, none given in Drupal\my_module\Plugin\RulesAction\MyActionClass->doExecute()
So my questions are :
- Do I need a context for rules action to work ?
- If yes, how can I find it and get it working ?
Here are the documentations I find (but rules is unfornately not very well documented for now):
Rules documentation for dev | RulesAction examples | Context documentation