Problem/Motivation

We would like to show different fields in the CSV than in the table. Idea came from https://www.drupal.org/project/vbo_export/issues/3098988. This have been backported to D7 by this patch. But, we also needed to hide a few more columns what we cannot exclude in the table. (For example: You have operations like edit, delete in your table, but there is no point to show it in the CSV).

Proposed resolution

diff --git a/sites/all/modules/vbo_export/vbo_export.module b/sites/all/modules/vbo_export/vbo_export.module
index a6b239874..147e713a7 100644
--- a/sites/all/modules/vbo_export/vbo_export.module
+++ b/sites/all/modules/vbo_export/vbo_export.module
@@ -78,6 +78,16 @@ function vbo_export_action_views_bulk_operations_form($options) {
     '#title' => t('Strip HTML tags'),
     '#default_value' => !empty($options['strip_tags']) ? $options['strip_tags'] : 0,
   );
+  $form['include_excluded'] = [
+    '#title' => t('Include fields excluded from display'),
+    '#type' => 'checkbox',
+    '#default_value' => isset($options['include_excluded']) ? $options['include_excluded'] : FALSE,
+  ];
+  $form['exclude_columns'] = [
+    '#title' => t('Exclude columns from the export. Comma separated list with field\'s name.'),
+    '#type' => 'textfield',
+    '#default_value' => isset($options['exclude_columns']) ? $options['exclude_columns'] : FALSE,
+  ];
 
   return $form;
 }
@@ -112,6 +122,21 @@ function vbo_export_action_base($node, $context, $theme, $file_extension) {
   $view->init_handlers();
   $view->init_style();
 
+  // If config option is set exclude some fields from display.
+  if ($context['settings']['exclude_columns']) {
+    $exclude_ids = explode(',', $context['settings']['exclude_columns']);
+    foreach ($exclude_ids as $key => $id) {
+      $exclude_ids[$key] = trim($id);
+    }
+  }
+
+  // If config option is set force export of fields hidden from display.
+  if ($context['settings']['include_excluded']) {
+    foreach ($view->field as $id => $field) {
+      $view->field[$id]->options['exclude'] = FALSE;
+    }
+  }
+
   // Get action data from current batch.
   $batch = &batch_get();
 
@@ -134,6 +159,9 @@ function vbo_export_action_base($node, $context, $theme, $file_extension) {
 
     // Generate header row.
     foreach ($view->field as $field_id => $field) {
+      if (isset($exclude_ids) && in_array($field_id, $exclude_ids)) {
+        continue;
+      }
       if ($field->options['exclude'] || $field_id == 'views_bulk_operations') {
         continue;
       }
@@ -161,7 +189,11 @@ function vbo_export_action_base($node, $context, $theme, $file_extension) {
   $entity_fields = reset($rendered_fields);
 
   $index = count($action_data['rows']);
+
   foreach ($action_data['header'] as $field_id => $title) {
+    if (isset($exclude_ids) && in_array($field_id, $exclude_ids)) {
+      continue;
+    }
     $action_data['rows'][$index][$field_id] = $entity_fields[$field_id];
     if (!empty($context['settings']['strip_tags'])) {
       $action_data['rows'][$index][$field_id] = html_entity_decode(strip_tags($action_data['rows'][$index][$field_id]));

Remaining tasks

As far as I know it is working well, but of course community have to test it.

User interface changes

We added 2 new configuration fields into VBO Export oprtation settings page.
1. "Include fields excluded from display" -> (checkbox) Adding excluded fields into the CSV.
2. "Exclude columns from the export. Comma separated list with field's name." -> (textfield) - Whenevet the field excluded ot not, you can get it deleted from the CSV. You can use the field's ID in a simple comma separated list. (for example: title, body, body_1, title_2)

API changes

No API changes.

Data model changes

No data model changes.

Comments

SunnyGambino created an issue. See original summary.

sunnygambino’s picture

Quick fix to avoid notices:

new file mode 100644
index 000000000..a4457a6b1
--- /dev/null
+++ b/sites/all/modules/vbo_export/vbo_export_notices_patch.patch
@@ -0,0 +1,22 @@
+diff --git a/sites/all/modules/vbo_export/vbo_export.module b/sites/all/modules/vbo_export/vbo_export.module
+index 147e713a7..857c2a366 100644
+--- a/sites/all/modules/vbo_export/vbo_export.module
++++ b/sites/all/modules/vbo_export/vbo_export.module
+@@ -123,7 +123,7 @@ function vbo_export_action_base($node, $context, $theme, $file_extension) {
+   $view->init_style();
+ 
+   // If config option is set exclude some fields from display.
+-  if ($context['settings']['exclude_columns']) {
++  if (!empty($context['settings']['exclude_columns'])) {
+     $exclude_ids = explode(',', $context['settings']['exclude_columns']);
+     foreach ($exclude_ids as $key => $id) {
+       $exclude_ids[$key] = trim($id);
+@@ -131,7 +131,7 @@ function vbo_export_action_base($node, $context, $theme, $file_extension) {
+   }
+ 
+   // If config option is set force export of fields hidden from display.
+-  if ($context['settings']['include_excluded']) {
++  if (!empty($context['settings']['include_excluded'])) {
+     foreach ($view->field as $id => $field) {
+       $view->field[$id]->options['exclude'] = FALSE;
+     }

sunnygambino’s picture

StatusFileSize
new1.07 KB
astonvictor’s picture

Status: Active » Closed (outdated)

D7 reached its EOL back in January 2025, and there is no active release for D7 for this module anymore.
Development or support is not planned for D7. All D7-related issues are marked as outdated in a bunch.

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.