How to transmit parameters to Rules Component upon using Rules Scheduler programmatically?

by Yakimkin Roman   Last Updated November 20, 2017 20:07 PM

Now I'm trying to create a Rules Scheduler task programmatically.

I've created a Rules Action with parameters and callback, also I've created a Rules Component with this Rules Action.

But upon trying to create the Rules Scheduler task programmatically I can't transmit it parameters for the Rules Component.

I'm using code, found here.

$now = new DateTime();
    $component = 'yrv_invitation_coupon_test_rule';
    $task_id = $now->getTimestamp();

    rules_action('schedule', ['component' => $component])
        ->executeByArgs([
            'date' => $now->getTimestamp()+10,
            'identifier' => $task_id,
            'param_uid' => 10,
            'param_rid' => 5,
        ]);

It works, but with default parameters.That is, executed Action in the Component can't get param "uid" with value = 10 and param "rid" with value = 5.

Could ou clarify me, how can I assign parameters ?

Here's my Action

$actions['yrv_invitation_coupon_user_remove_role'] = [
        'label' => t('Remove a role assigned upon activation an invitation coupon'),
        'group' => t('System'),
        'base' => 'yrv_invitation_coupon_remove_role_callback',
        'parameter' => [
            'uid' => [
                'type' => 'integer',
                'label' => t('User ID'),
                'default value' => 1,
            ],
            'rid' => [
                'type' => 'integer',
                'label' => t('Role ID'),
                'default value' => 1,
            ]
        ],
    ];

And here's my Rule Component

$rule = rule();
    $rule->label = 'YRV Invitation coupon test Rule';
    $rule->class = 'Rule';
    $rule->action('yrv_invitation_coupon_user_remove_role', ['uid' => 1, 'rid' => 1]);
    $rule->active = TRUE;

    $configs['yrv_invitation_coupon_test_rule'] = $rule;
Tags : 7 rules


Related Questions


Clone nodes and change fields with Rules and VBO

Updated May 20, 2015 20:03 PM