0

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;

1 Answer 1

0

Fortunately, I managed to find the solution.

Namely, a Rule component should be created such way.

function yrv_invitation_coupon_default_rules_configuration()
{
    $configs = [];

    $rule = rule([
        'uid' => [
            'type' => 'integer',
            'label' => t('User ID'),
        ],
        'rid' => [
            'type' => 'integer',
            'label' => t('Role ID'),
        ],
    ]);
    $rule->label = 'YRV Invitation coupon test Rule';
    $rule->class = 'Rule';
    $rule->action('yrv_invitation_coupon_user_remove_role', []);
    $rule->active = TRUE;

    $configs['yrv_invitation_coupon_test_rule'] = $rule;

    return $configs;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.