1

This seems like it would be a common application but not sure if it is doable. I have a view (d7, views3) that is displaying fields in views bulk operation format from a content type (call it general). For each row the user selects, I want to create a node of a separate content type (call it userspecific) made up of the user id and some of the fields from the general content type. Is this something that is possible using VBO ??

2

This can be done using views bulk operations. But you may have to implement hook_actions_info in a custom module to create an action and the use that action in the views bulk operation.

Following code illustrates the process.

function custom_test_action_info(){
  return array(
    'custom_test_create_new_node' => array(
      'type' => 'node',
      'label' => t('Create New Page'),
      'configurable' => FALSE,
      'triggers' => array('any'),
    ),
    );
}

function custom_test_create_new_node($node, $context = array()){
  global $user;
  $page_node = new stdClass();
  $page_node->type = 'page';
  $page_node->status = 1;
  $page_node->title = $node->title;
  $page_node->field_body[LANGUAGE_NONE][0]['value'] = $node->field_body[LANGUAGE_NONE][0]['value'];
  $page_node->uid = $user->uid;
  node_save($page_node);
}

After saving this code flush the drupal cache and the views bulk operations form will have the action available.

views bulk operation config form

After saving the view you will get the operation available in the views bulk operation page.

New action available in the dropdown of the views bulk operation page

select a node and then execute the operation and you will have a new basic page created.

i am attaching an export of the view which i created you can import this view in your system and give a try to understand the workflow.

Export code of the view:

$view = new view();
$view->name = 'test_vbo_node_creation';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Test VBO node creation';
$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['title'] = 'Test VBO node creation';
$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['pager']['options']['items_per_page'] = '10';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
/* Field: Content: Body */
$handler->display->display_options['fields']['body']['id'] = 'body';
$handler->display->display_options['fields']['body']['table'] = 'field_data_body';
$handler->display->display_options['fields']['body']['field'] = 'body';
/* 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::custom_test_create_new_node' => array(
    'selected' => 1,
    '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_delete_revision' => 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' => 1,
    'label' => 'Create a new node',
  ),
  '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' => 0,
    'postpone_processing' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
  ),
  'action::node_unpublish_by_keyword_action' => array(
    'selected' => 0,
    'postpone_processing' => 0,
    'skip_confirmation' => 0,
    'override_label' => 0,
    'label' => '',
  ),
);
/* 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';
/* 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(
  'article' => 'article',
);

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'test-vbo-node-creation';
  • Super stuff ! I created the custom code and was able to create the action, then see it in VBO and select it. I brought up the page, selected one of the rows, and pressed the button. It created a new node with the title and user id but the problem I am having is with my other fields getting values in them. All but one are text fields and I did them like you did the body field. It seems to be a problem on the $page_node side because I tried just putting literal values in there but they didn’t show up. Any thoughts ?? – ronnienorwood Jan 1 '14 at 0:00
  • Now fields are being created but does anyone know how to query the rows to determine which ones have the checkbox checked ?? It looks like the field is called views_bulk_operations but when I display it, the value is NULL on all rows even though I checked the first one. – ronnienorwood Jan 1 '14 at 23:56
  • Hi @ronnienorwood, you don't have to query the rows to determine which ones have the checkbox checked. In your action callback you will get only those nodes that have been selected in the views bulk operation. If your use case is something different please let me know more details. – Sudheesh Damodaran Jan 2 '14 at 5:43
  • Probably is a little bit different use case in that I used a date field with the repeat option and had to tell the view to create a row for each date by unchecking ‘display all values in the same row’ on the date field. So then I ended up creating a foreach loop in the custom code to handle the individual rows. foreach ($rows as $row=>$value) { $page_node->field_date_class['und'][0]['value'] = $node->field_date_class['und'][$row]['value']; node_save($page_node); } This created nodes for all rows so that’s why I was trying to figure out which rows had been selected. – ronnienorwood Jan 3 '14 at 1:45

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.