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

fago’s picture

Title: Component variables that are not parameters » Make providing components in code useful.
Component: Rules Core » Rules Engine
StatusFileSize
new4.89 KB

Let'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.

fago’s picture

StatusFileSize
new21.13 KB

ok, 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:

     #1057484 patch by me and klausi towards making components in code more useful:
      * Allow the definition of variables that do not require a passed argument, as useful for returning variables that are not passed as parameter.
      * Improved the data_set action to be able to set variables too.
      * Fix handling of NULL values so Rules bails out if NULL values are passed as argument to an action. Including test coverage.
      * Introduced the optional 'allow null' key for parameters, so actions can go with NULL values. Made use of that for the data_set action.
      * Added tests for having components providing new variables.

I leave the issue open for the missing point:
- Adapt the UI so the variables cannot be edited for component in code.

klausi’s picture

StatusFileSize
new765 bytes

A small follow-up to fix the UI form validation.

fago’s picture

Status: Needs review » Fixed

thanks, 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.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.