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.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | vbo_export_notices_patch.patch | 1.07 KB | sunnygambino |
| exclude_columns_by_id.patch | 2.64 KB | sunnygambino |
Comments
Comment #2
sunnygambino commentedQuick fix to avoid notices:
Comment #3
sunnygambino commentedComment #4
astonvictor commentedD7 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.