Here is an example of providing a default rule set:
$variables = array(
'job_id' => array(
'type' => 'integer',
'label' => t('Job id'),
),
'eq_job' => array(
'type' => 'eq_job',
'label' => t('Job'),
'parameter' => FALSE,
),
);
$rule_set = rules_rule_set($variables, array('eq_job'));
"job_id" is a normal parameter variable that must be present and that is visible in the UI as parameter variable. "eq_job" is a variable that should only be provided by the component and should not be considered a parameter. Therefore I introduced the "parameter" option to indicate whether a variable should be used as parameter or not (default: TRUE). Patch attached.
Comments
Comment #1
fagoLet's improve the issue title to what we want to achieve:
* Define a component, e.g. rule set in code such that the variables are defined and fixed, but the content can be overridden / configured via the UI. That way a module can define a component in code and rely on the defined variables, such that the required parameters and returned variables stay, but users are still able to customize the content, i.e. the rules of a rule set.
@patch:
I've updated the patch so it basically works for me. In order to make that properly work, we also need to ensure the data_set action works properly with directly setting variables.
todo:
- Make the data_set action work with setting variables that are not wrapped.
- Adapt the UI so the variables cannot be edited for component in code.
- Let's add a test case for that.
Comment #2
fagook, I've completed the todos except for the UI stuff and commit it. Beside that, I've also fixed the handling of NULL values as this was required for this to work.
I've attached the patch of what I've commited. Summary:
I leave the issue open for the missing point:
- Adapt the UI so the variables cannot be edited for component in code.
Comment #3
klausiA small follow-up to fix the UI form validation.
Comment #4
fagothanks, I improved the comment and committed it.
>- Adapt the UI so the variables cannot be edited for component in code.
We've fixed that in a separate issue, so we can close this one now.