You are here

function views_bulk_operations_action_form_operation in Views Bulk Operations (VBO) 6

Form callback to update an action form when a new action is selected in views_bulk_operations_action form.

1 string reference to 'views_bulk_operations_action_form_operation'
views_bulk_operations_menu in ./views_bulk_operations.module
Implementation of hook_menu().

File

./views_bulk_operations.module, line 1336
Allows operations to be performed on items selected in a view.

Code

function &views_bulk_operations_action_form_operation(&$form, $form_state) {

  // TODO: Replace this with autoloading of style plugin and view definitions to use $form['#plugin'].
  $view = views_get_view($form_state['values']['view_vid']);
  $vd = new views_bulk_operations_destructor($view);

  // this will take care of calling $view->destroy() on exit.
  foreach (array_keys($view->display) as $display) {
    $display_options =& $view->display[$display]->display_options;
    if (isset($display_options['style_plugin']) && $display_options['style_plugin'] == 'bulk') {
      $plugin = views_get_plugin('style', $display_options['style_plugin']);
      $plugin
        ->init($view, $view->display[$display], $display_options['style_options']);
      break;
    }
  }
  $form['#operation'] = $plugin
    ->get_operation_info($form_state['values']['operation_key']);
  if ($form['#operation']['configurable']) {
    $form['operation_arguments']['wrapper'] = array(
      '#type' => 'markup',
      '#value' => '',
      '#prefix' => '<div id="operation-wrapper">',
      '#suffix' => '</div>',
    );
    $form['operation_arguments']['wrapper']['operation_form'] = _views_bulk_operations_action_form($form['#operation'], $plugin->view, NULL, $form['#operation']['options']['settings']);
    if (!empty($form['#operation']['form properties'])) {
      foreach ($form['#operation']['form properties'] as $property) {
        if (isset($form['operation_arguments']['wrapper']['operation_form'][$property])) {
          $form[$property] = $form['operation_arguments']['wrapper']['operation_form'][$property];
        }
      }
    }
    $form['operation_arguments']['wrapper']['operation_arguments'] = array(
      '#type' => 'textarea',
      '#title' => t('Operation arguments'),
      '#description' => t('Enter PHP script that will assemble the operation arguments (and will override the operation form above).
                           These arguments should be of the form: <code>return array(\'argument1\' => \'value1\', ...);</code>
                           and they should correspond to the values returned by the action\'s form submit function.
                           The variables <code>&$object</code> and <code>$context</code> are available to this script.
                          '),
    );
  }
  else {
    $form['operation_arguments']['wrapper']['operation_form'] = array(
      '#type' => 'markup',
      '#value' => t('This operation is not configurable.'),
    );
    $form['operation_arguments']['wrapper']['operation_arguments'] = array(
      '#type' => 'value',
      '#value' => '',
    );
  }
  return $form['operation_arguments']['wrapper'];
}