This topic contains 2 replies, has 2 voices, and was last updated by Dmitry Khrysev 9 years, 9 months ago.
- Topic
I try to create custom workflow transition action to implement message sending in AQ by STOMP.
I created my own new bundle Test\Bundle\STOMPBundle without any inheritance, added data to services.yml and wrote my action as full copy of assign_value action.
Test\Bundle\STOMPBundle\Resources\config\services.yml:
12345678910parameters:oro_workflow.action.send_stomp_message.class: Test\Bundle\STOMPBundle\Model\Action\SendSTOMPMessageservices:oro_workflow.action.send_stomp_message:class: %oro_workflow.action.send_stomp_message.class%tags:- { name: oro_workflow.action, alias: send_stomp_message }Test\Bundle\STOMPBundle\Model\Action\SendSTOMPMessage:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115<?phpnamespace Test\Bundle\STOMPBundle\Model\Action;use Oro\Bundle\WorkflowBundle\Exception\InvalidParameterException;use Oro\Bundle\WorkflowBundle\Model\Action\AbstractAction;use Oro\Bundle\WorkflowBundle\Model\Condition\ConditionInterface;use Oro\Bundle\WorkflowBundle\Model\ContextAccessor;use Symfony\Component\PropertyAccess\PropertyPath;class SendSTOMPMessage extends AbstractAction{/*** @var array*/protected $assigns = array();/*** {@inheritdoc}*/protected function executeAction($context){foreach ($this->assigns as $assignOptions) {$this->contextAccessor->setValue($context,$this->getAttribute($assignOptions),$this->getValue($assignOptions));}}/*** Get target.** @param array $options* @return mixed*/protected function getAttribute(array $options){return array_key_exists('attribute', $options) ? $options['attribute'] : $options[0];}/*** Get value.** @param array $options* @return mixed*/protected function getValue(array $options){return array_key_exists('value', $options) ? $options['value'] : $options[1];}/*** {@inheritdoc}*/public function initialize(array $options){if ($this->isMassAssign($options)) {foreach ($options as $assignOptions) {$this->addAssign($assignOptions);}} else {$this->addAssign($options);}return $this;}/*** @param array $options* @throws InvalidParameterException*/protected function addAssign(array $options){if (count($options) != 2) {throw new InvalidParameterException('Attribute and value parameters are required.');}if (!isset($options['attribute']) && !isset($options[0])) {throw new InvalidParameterException('Attribute must be defined.');}if (!array_key_exists('value', $options) && !array_key_exists(1, $options)) {throw new InvalidParameterException('Value must be defined.');}if (!($this->getAttribute($options) instanceof PropertyPath)) {throw new InvalidParameterException('Attribute must be valid property definition.');}$this->assigns[] = $options;}/*** @param array $options* @return bool*/protected function isMassAssign(array $options){if (empty($options)) {return false;}foreach ($options as $element) {if (!is_array($element)) {return false;}}return true;}}Usage in workflow.yml (same as for assign_value action):
1234567...post_actions:- @send_stomp_message:- [$probability, 0.5]...When I call my action I get error:
123Catchable fatal error: Argument 1 passed to Oro\Bundle\WorkflowBundle\Model\Action\AbstractAction::__construct() must be an instance of Oro\Bundle\WorkflowBundle\Model\ContextAccessor, none given, called in /home/vagrant/orocrm/app/cache/dev/appDevDebugProjectContainer.php on line 16791 and defined in /home/vagrant/orocrm/vendor/oro/platform/src/Oro/Bundle/WorkflowBundle/Model/Action/AbstractAction.php on line 23But when I replace my test action with original assign_value action everything is fine!
It seems that in input of my action all arguments put as null. What I do wrong? How I should declare my action in right way?
The forum ‘OroCRM – Programming Questions’ is closed to new topics and replies.