Right now the rules action config form doesn't have access to the selected entity, which severely limits the available tokens. That needs to change :)

CommentFileSizeAuthor
#7 1172346-vbo-rules.patch1.49 KBbojanz
#5 vbo_rules.patch1.61 KBfago
#4 1172346.patch1.03 KBbojanz

Comments

bojanz’s picture

Of course, we can't entity_load() everything, but there might be a trick that could allow us to have the tokens available. Will see with fago.

fago’s picture

oh, that works only if you have an action set... e.g.

$set = rules_action_set(array('entity' => array('type' => 'entity', 'label' => t('entity'))));
$set->action('component_foo', array('VAR:select' => 'entity'));
$set->form($form, $form_state);

where VAR is the name of the parameter that needs the entity..

If you need to get the action from inside the set it works that way:

$actions = $set->actions();
echo $actions[0]->label();
fago’s picture

Realized the example doesn't fit the use-case as we only want to embed the action form, not the form of the whole action-set.
E.g. that way

$set = rules_action_set(array('entity' => array('type' => 'entity', 'label' => t('entity'))));
$action = rules_action('component_foo', array('VAR:select' => 'entity'));
$set->action($action);
$action->form($form, $form_state);
bojanz’s picture

Status: Active » Needs review
StatusFileSize
new1.03 KB

Here's a first patch.

It shows all tokens as it should but the form can't be submitted, it fails validation complaining that $test is not present (the entity param of the component I'm executing, and whose form I'm nuking with unset since I'm passing it to ->execute() later on).

fago’s picture

StatusFileSize
new1.61 KB

You'll need to fix the var-names of my example.. ;)

See my attached patch. I've no time to test it right now, but basically I think it should work like that.

wjaspers’s picture

subbing

bojanz’s picture

StatusFileSize
new1.49 KB
+  // It should work without having to specify that manually? Doesn't it?
   require_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'rules') . "/ui/ui.forms.inc";

Yes, it works without that line now. However, back in may when that was written, I was getting fatal errors without it. Maybe an issue was fixed in the meantime?

I tested the patch, and it still only worked if the first component param was named like the entity type.
Attaching a patch that works (in my limited testing). The main change is to specify $entity_key instead of $entity_type in rules_action_set().
After that's done, rules_action() works properly even without the second parameter ($var . ':select') -> is there a difference between specifying it and not specifying it?

fago’s picture

>Maybe an issue was fixed in the meantime?
Sounds so. I don't remember one though. Anyway, it shouldn't be required so let's better go without it.

>After that's done, rules_action() works properly even without the second parameter ($var . ':select') -> is there a difference between specifying it and not specifying it?

If you leave it out and there is no value, rules defaults to use the variable that has the same name as the parameter of the action. So if the action-parameter would be named different, it would stop working. Thus better add it in.

bojanz’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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