1

I am interested on this scenario: After a user is assigned a role,all his published nodes get unpublished. I am interested in doing this with rules and VBO. I tried but no luck. I used :Event:User profile is update Action:Load all node with VBO. Seems I am missing something.Anyone help? thanks

1

I would instead create a Views Loop using the Views Rules module. You can create a view and have the rule loop through all the rows that the view outputs.

Edit:

For Example, I want to send an e-mail to all user's attached to a node registration. So I needed to do the following:

  1. Create a view with a Rules Display. Field: User E-mail. Contextual Filter: NID (Screenshot: http://i.imgur.com/rcvdMyn.jpg).
  2. In the Views Rule Settings - Parameters: I specified the parameter's label and name, that wil need to match the Views Loop Data selector (Step 4) for the Views Contextual filter. (Screenshot: http://i.imgur.com/MFA7mxk.jpg)
  3. In the Views Rule Settings - Row Variables: I specified which field should be enabled for Rules, and how it should be passed back to Rules. (Screenshot: http://i.imgur.com/U7fkzjj.jpg)
  4. I then created a Views Loop in my Rule matching the Parameters and Row Variables in my view (Screenshot: http://i.imgur.com/hGziOtK.jpg)
  5. I then created the action "Send mail" under the Views loop using the now available token that was specified in the View. (Screenshot: http://i.imgur.com/chlKc7x.jpg)

And that's it. If you want to test your output rather than your unpublish action. I would recommend using the action "Show a message on the site".

In your case your contextual filter is most likely your UID and NID as your field. I used my example as a proof of concept.

Edit 2:

Exported View:

$view = new view();
$view->name = 'waiting_list_user_list';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'users';
$view->human_name = 'Waiting List User list';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['access']['perm'] = 'access user profiles';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['style_options']['default_row_class'] = FALSE;
$handler->display->display_options['style_options']['row_class_special'] = FALSE;
$handler->display->display_options['row_plugin'] = 'fields';
/* Relationship: User: Registration */
$handler->display->display_options['relationships']['registration']['id'] = 'registration';
$handler->display->display_options['relationships']['registration']['table'] = 'users';
$handler->display->display_options['relationships']['registration']['field'] = 'registration';
$handler->display->display_options['relationships']['registration']['label'] = 'User Registration';
/* Relationship: Registration: Registration to Node */
$handler->display->display_options['relationships']['registration_related_node']['id'] = 'registration_related_node';
$handler->display->display_options['relationships']['registration_related_node']['table'] = 'registration';
$handler->display->display_options['relationships']['registration_related_node']['field'] = 'registration_related_node';
$handler->display->display_options['relationships']['registration_related_node']['relationship'] = 'registration';
/* Field: User: E-mail */
$handler->display->display_options['fields']['mail']['id'] = 'mail';
$handler->display->display_options['fields']['mail']['table'] = 'users';
$handler->display->display_options['fields']['mail']['field'] = 'mail';
$handler->display->display_options['fields']['mail']['label'] = '';
$handler->display->display_options['fields']['mail']['alter']['trim_whitespace'] = TRUE;
$handler->display->display_options['fields']['mail']['alter']['strip_tags'] = TRUE;
$handler->display->display_options['fields']['mail']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['mail']['element_default_classes'] = FALSE;
$handler->display->display_options['fields']['mail']['link_to_user'] = '0';
/* Contextual filter: Content: Nid */
$handler->display->display_options['arguments']['nid']['id'] = 'nid';
$handler->display->display_options['arguments']['nid']['table'] = 'node';
$handler->display->display_options['arguments']['nid']['field'] = 'nid';
$handler->display->display_options['arguments']['nid']['relationship'] = 'registration_related_node';
$handler->display->display_options['arguments']['nid']['default_argument_type'] = 'fixed';
$handler->display->display_options['arguments']['nid']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['nid']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['nid']['summary_options']['items_per_page'] = '25';
/* Filter criterion: User: Active */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'users';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = '1';
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Filter criterion: Registration: State entity */
$handler->display->display_options['filters']['state']['id'] = 'state';
$handler->display->display_options['filters']['state']['table'] = 'registration';
$handler->display->display_options['filters']['state']['field'] = 'state';
$handler->display->display_options['filters']['state']['relationship'] = 'registration';
$handler->display->display_options['filters']['state']['value'] = array(
  'waitlist' => 'waitlist',
);

/* Display: Rules */
$handler = $view->new_display('views_rules', 'Rules', 'views_rules_1');
$handler->display->display_options['pager']['type'] = 'some';
$handler->display->display_options['rules_parameter'] = array(
  'nid' => array(
    'enabled' => 1,
    'type' => 'integer',
    'label' => 'nid',
    'name' => 'nid',
  ),
);
$handler->display->display_options['rules_variables'] = array(
  'mail' => array(
    'enabled' => 1,
    'rendered' => 0,
    'type' => 'token',
    'label' => 'User: E-mail',
    'name' => 'mail',
  ),
);

Exported Rule

{ "rules_waiting_list_e_mail_after_registration_deletion" : {
    "LABEL" : "Waiting List E-mail after Registration Deletion",
    "PLUGIN" : "reaction rule",
    "ACTIVE" : false,
    "REQUIRES" : [ "rules", "rules_i18n", "registration" ],
    "ON" : { "registration_delete" : [] },
    "IF" : [
      { "data_is" : { "data" : [ "registration:state:name" ], "value" : "complete" } }
    ],
    "DO" : [
      { "entity_fetch" : {
          "USING" : { "type" : "node", "id" : [ "registration:entity-id" ] },
          "PROVIDE" : { "entity_fetched" : { "node_id" : "node_id" } }
        }
      },
      { "VIEW LOOP" : {
          "VIEW" : "waiting_list_user_list",
          "DISPLAY" : "views_rules_1",
          "USING" : { "nid" : [ "node-id:nid" ] },
          "ROW VARIABLES" : { "mail" : { "mail" : "User: E-mail" } },
          "DO" : [
            { "mail" : {
                "to" : [ "mail" ],
                "subject" : "test",
                "message" : "Test",
                "language" : [ "" ]
              }
            }
          ]
        }
      }
    ]
  }
}
  • Hi,thanks for the answer,one question:After adding the View loop and the action "Unpublish content" ,I am not able to show which content to unpublish.I am asked to select this but I cannot.Any thoughts? – sokratis Oct 22 '13 at 10:08
  • I mean,how do I pass the nodes from the View Rule to the Action "Unpublish content" ? – sokratis Oct 22 '13 at 10:19
  • Could you please paste the rule here? – sokratis Oct 22 '13 at 10:54
  • I edited my original post. I hope this helps! – NWOM Oct 22 '13 at 11:05
  • I have done exactly what you said,there is only one final issue:When making the action to unpublish the nodes,it is not accepted.I take this message:"Data selector nid for parameter node is invalid." – sokratis Oct 22 '13 at 12:35
1

I finally found how to do this with VBO . Here is a video which helped me. http://drupalize.me/videos/using-vbo-load-list-objects-rules I hope it helps someone else. THanks!

  • I will have to check that out. I haven't used VBO with rules yet. And obviously as we've seen, Views Rules can't solve the problem every time :). Thanks – NWOM Oct 24 '13 at 6:05
  • The secret is to add the Unpublish action inside the loop so as to have the token available. – sokratis Oct 24 '13 at 9:02
0

Here is the view

$view = new view();
$view->name = 'published_cars_of_a_user';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Published cars of a user';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* Field: Content: Nid */
$handler->display->display_options['fields']['nid']['id'] = 'nid';
$handler->display->display_options['fields']['nid']['table'] = 'node';
$handler->display->display_options['fields']['nid']['field'] = 'nid';
$handler->display->display_options['fields']['nid']['label'] = '';
$handler->display->display_options['fields']['nid']['element_label_colon'] = FALSE;
/* Sort criterion: Content: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Contextual filter: Content: Author uid */
$handler->display->display_options['arguments']['uid']['id'] = 'uid';
$handler->display->display_options['arguments']['uid']['table'] = 'node';
$handler->display->display_options['arguments']['uid']['field'] = 'uid';
$handler->display->display_options['arguments']['uid']['default_argument_type'] = 'fixed';
$handler->display->display_options['arguments']['uid']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['uid']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['uid']['summary_options']['items_per_page'] = '25';
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Filter criterion: Content: Type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'node';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['value'] = array(
  'car' => 'car',
);

/* Display: Content pane */
$handler = $view->new_display('panel_pane', 'Content pane', 'panel_pane_1');
$handler->display->display_options['defaults']['fields'] = FALSE;
/* Field: Content: Nid */
$handler->display->display_options['fields']['nid']['id'] = 'nid';
$handler->display->display_options['fields']['nid']['table'] = 'node';
$handler->display->display_options['fields']['nid']['field'] = 'nid';
$handler->display->display_options['fields']['nid']['label'] = '';
$handler->display->display_options['fields']['nid']['element_label_colon'] = FALSE;
/* Field: Bulk operations: Content */
$handler->display->display_options['fields']['views_bulk_operations']['id'] = 'views_bulk_operations';
$handler->display->display_options['fields']['views_bulk_operations']['table'] = 'node';
$handler->display->display_options['fields']['views_bulk_operations']['field'] = 'views_bulk_operations';
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['display_type'] = '0';
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['enable_select_all_pages'] = 1;
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['force_single'] = 0;
$handler->display->display_options['fields']['views_bulk_operations']['vbo_settings']['entity_load_capacity'] = '10';
$handler->display->display_options['fields']['views_bulk_operations']['vbo_operations'] = array(
  'action::node_assign_owner_action' => array(
    'selected' => 0,
    'postpone_processing' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
  ),
  'action::views_bulk_operations_delete_item' => array(
    'selected' => 0,
    'postpone_processing' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
  ),
  'action::views_bulk_operations_script_action' => array(
    'selected' => 0,
    'postpone_processing' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
  ),
  'action::flag_node_action' => array(
    'selected' => 0,
    'postpone_processing' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
  ),
  'action::node_make_sticky_action' => array(
    'selected' => 0,
    'postpone_processing' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
  ),
  'action::node_make_unsticky_action' => array(
    'selected' => 0,
    'postpone_processing' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
  ),
  'action::views_bulk_operations_modify_action' => array(
    'selected' => 0,
    'postpone_processing' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
    'settings' => array(
      'show_all_tokens' => 1,
      'display_values' => array(
        '_all_' => '_all_',
      ),
    ),
  ),
  'action::views_bulk_operations_argument_selector_action' => array(
    'selected' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
    'settings' => array(
      'url' => '',
    ),
  ),
  'action::node_promote_action' => array(
    'selected' => 0,
    'postpone_processing' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
  ),
  'action::node_publish_action' => array(
    'selected' => 0,
    'postpone_processing' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
  ),
  'action::node_unpromote_action' => array(
    'selected' => 0,
    'postpone_processing' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
  ),
  'action::node_save_action' => array(
    'selected' => 0,
    'postpone_processing' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
  ),
  'action::system_send_email_action' => array(
    'selected' => 0,
    'postpone_processing' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
  ),
  'action::node_unpublish_action' => array(
    'selected' => 1,
    'postpone_processing' => 0,
    'skip_confirmation' => 1,
    'override_label' => 0,
    'label' => '',
  ),
  'action::node_unpublish_by_keyword_action' => array(
    'selected' => 0,
    'postpone_processing' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
  ),
);

/* Display: Rules */
$handler = $view->new_display('views_rules', 'Rules', 'views_rules_1');
$handler->display->display_options['pager']['type'] = 'some';
$handler->display->display_options['rules_parameter'] = array(
  'uid' => array(
    'enabled' => 1,
    'type' => 'integer',
    'label' => 'Content: Author uid',
    'name' => 'uid',
  ),
);
$handler->display->display_options['rules_variables'] = array(
  'nid' => array(
    'enabled' => 1,
    'rendered' => 0,
    'type' => 'integer',
    'label' => 'Content: Nid',
    'name' => 'nid',
  ),
);

And here is the rule

{ "rules_unpublish_all_emporos_expired_nodes" : {
    "LABEL" : "Unpublish all emporos expired nodes",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules" ],
    "ON" : { "user_update" : [] },
    "DO" : [
      { "VIEW LOOP" : {
          "VIEW" : "published_cars_of_a_user",
          "DISPLAY" : "views_rules_1",
          "USING" : { "uid" : [ "account:uid" ] },
          "ROW VARIABLES" : { "nid" : { "nid" : "Content: Nid" } },
          "DO" : []
        }
      }
    ]
  }
}
  • This Rule appears to be incomplete... it doesn't contain the "unpublish" action you were trying to achieve. I am working on a similar situation... I need to unpublish all nodes by a user when a specific event occurs on the website. I cannot get the Rule to provide the needed data selector. Can you please share the complete Rule code? – hockey2112 May 10 '18 at 18:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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