You are here

function gathercontent_views_bulk_operations_form_alter in GatherContent 7.3

Implements hook_views_bulk_operations_form_alter().

Alter VBO confirm form for gathercontent_update action and replace submit callback, so we can use custom batch.

File

./gathercontent.module, line 1138

Code

function gathercontent_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) {
  if ($form_state['step'] === 'views_bulk_operations_confirm_form') {
    switch ($form_state['operation']->operationId) {
      case 'action::gathercontent_update':
        $array = array(
          implode('+', array_filter($form_state['values']['views_bulk_operations'])),
        );
        $view = views_get_view('update');
        $view
          ->set_display("block_1");
        $view
          ->set_arguments($array);
        $view
          ->preview();
        $content = $view
          ->render();
        $form['description']['#markup'] = '<p>' . t('Please review your selection before updating.') . '</p>' . $content;
        $form['#vbo_confirm_form_title'] = format_plural(count(array_filter($form_state['values']['views_bulk_operations'])), 'Confirm update selection (@count item)', 'Confirm update selection (@count items)');
        $form['node_update_method'] = [
          '#type' => 'radios',
          '#required' => TRUE,
          '#title' => t('Content update method'),
          '#default_value' => variable_get('gathercontent_node_update_method', 'always_update'),
          '#options' => [
            'always_create' => t('Always create new Content'),
            'update_if_not_changed' => t('Create new Content if it has changed since the last import'),
            'always_update' => t('Always update existing Content'),
          ],
        ];
        $form['actions']['submit']['#submit'] = array(
          'gathercontent_views_vbo_update',
        );
        break;
      case 'action::gathercontent_upload':
        $array = array(
          implode('+', array_filter($form_state['values']['views_bulk_operations'])),
        );
        $view = views_get_view('update');
        $view
          ->set_display("block_1");
        $view
          ->set_arguments($array);
        $view
          ->preview();
        $content = $view
          ->render();
        $form['description']['#markup'] = '<p>' . t('Please review your selection before upload.') . '</p>' . $content;
        $form['#vbo_confirm_form_title'] = format_plural(count(array_filter($form_state['values']['views_bulk_operations'])), 'Confirm upload selection (@count item)', 'Confirm upload selection (@count items)');
        $form['actions']['submit']['#submit'] = array(
          'gathercontent_views_vbo_upload',
        );
        break;
    }
  }
}