When using this with rules ability to run VBO's, I get an error in the rules settings:

invalid argument supplied for foreach()" at line 103.

Basically because on line 102 ( $view = views_get_current_view(); ) we are loading the current view. But in rules, there is no current view.

So I did something like this:

drupal_add_js(drupal_get_path('module', 'smsbulk') .'/smsbulk.js');
  $options = array(t('- select -'));
//added/changed stuff below this line - this is line 101
if (!isset($context['view']->field)) {
  $view = views_get_view($context['view']->name);
  $view = $context['view']->display['default']->display_options;
  foreach ($view['fields'] as $field) {
    $field_alias = $field['table'] .'_' . $field['field'];
    $options += array($field_alias => $field['label']);
  }
}
else {
  $view = views_get_current_view();
  foreach ($view->field as $field) {
    $options += array($field->field_alias => $field->options['label']);
  }
}
//added/changed stuff above this line
 $form['sms_field'] = array(
    '#type' => 'select',

This allows me to set stuff inside of rules, but the info isn't stored anywhere.

Comments

gunzip’s picture

thank you for reporting. what do you mean exactly with "the info isn't stored anywhere" ?

that0n3guy’s picture

StatusFileSize
new6.04 KB

I didn't know what I was talking about. It is stored.

Attached is a patch that will help with rules integration. Its mostly working except for the token replacement stuff. Right now it shows all the node tokens (most wont work right). I'm not sure how to get the "rules argument object" for use in token_replace. Right now it uses the object from the view for token replace.

Take a look at it and let me know what you think.

that0n3guy’s picture

Just to clarify, I want to get the rules object (the same $object that is here:
views_bulk_operations_action(&$object, $context) (In VBO.module)

So I can use it for token replace in this module (in rules).

that0n3guy’s picture

StatusFileSize
new6.54 KB

Newer patch to go along with this one: http://drupal.org/node/987786#comment-3783790

Lets you use the rules argument object for tokens.

that0n3guy’s picture

Status: Active » Needs review
StatusFileSize
new6.5 KB

Ooops... small error.

ignore the last patch.

gunzip’s picture

thank you for the patch. there are still some issues to cover:

1. the patch assumes that the only gateway option is the country field. this states for ie. clickatell gateway, but the gateway options aren't fixed and may vary so this line:

   $form['gateway']['country']['#default_value'] = isset($context['gateway_options']) ? $context['gateway_options'] 

has to be fixed somehow.

2. the patch assumes that we're always dealing with node object:

$form['view']['token_help']['help'] = array(
  '#value' => theme('token_help', 'node'),
);

but this isn't always true as tokens may regard users and othere entities as well
(this is the reason I had to code my own token management)

Finally i guess this code:

 if (!isset($context['view']->field)) {
   $view = views_get_view($context['view']->name);
   $view = $context['view']->display['default']->display_options;
   if(!isset($context['view_vid'])){
     foreach ($view['fields'] as $field) {
	$field_alias = $field['table'] .'_' . $field['field'];
        $options += array($field_alias => $field['label']);
 $form += sms_bulk_get_gateway_options();
     }
   }
   else {
     $options += array($context['sms_field'] => $context['sms_field']);
   }
 }
 else {
   $view = views_get_current_view();
   foreach ($view->field as $field) {
     $options += array($field->field_alias => $field->options['label']);
   }
}

can be changed into:

  $view = views_get_current_view();
  if (empty($view) and $context['view']) {
    $view = views_get_view($context['view']->name);
    $view->build('default');
  }
  foreach ($view->field as $field) {
    $options += array($field->field_alias => $field->options['label']);
  }
gunzip’s picture

StatusFileSize
new1.35 KB

new patch attached. it looks like the rule vbo settings page doesn't load the correct view in the beginning.