Will be good to see integration with Views Bulk Operations module. This add feature for exporting to csv and other format many custom selected data, instead of building separated view for them.
You can do this via provide some rules via hook_node_operations() and re-use your current export functions.
Good example that exports to csv you can find here: http://britesparkz.com/tennessee-drupal-blogs/ubercart-vbo-and-cvs-exports
| Comment | File | Size | Author |
|---|---|---|---|
| #40 | interdiff-21-39.txt | 1.12 KB | Jorrit |
| #40 | 1436726-views_data_export-vbo_csv_export-39.patch | 3.06 KB | Jorrit |
| #36 | vbo.png | 23.56 KB | retiredpro |
| #30 | interdiff-1436726-21-28.txt | 6.69 KB | jgullstr |
| #28 | views_data_export-vbo_csv_export-1436726-28.patch | 5 KB | jgullstr |
Comments
Comment #1
bojanz commentedhook_node_operations() is not supported by VBO for D7.
You either provide a core action, or a rules action (or even a complete rules component).
Comment #2
murzFor Drupal 7.x you can use hook_action_info(). I done for my needs csv export in custom module, here is example:
It is very basic and not configurable, but works for my needs very good.
This is not views-related code, but will be good to see this functional in this module or separate module.
Comment #3
texas-bronius commentedHey @Murz, pretty slick. Thanks for sharing this info-- works like a boss!
I had a spot of trouble with it (only got one record out from your snippet adapted for my use case) and wanted to share my observations and load this issue queue with some SEO on this elegant solution to giving Views Bulk Operation the ability to export CSV of the selected records. Maybe you can comment on them and confirm?
* It appears that you've configured your VBO action not as aggregate => TRUE and yet it still runs. This is because you're iterating the whole set of VBO provided entities against a growing,
staticvariable and terminating iteration on VBO's $context variable status of completion field.* Note that setting aggregate => TRUE breaks the solution and only returns results for 1 record
* what is configurable => FALSE in this case?
[edit: OOps, I misread the title of this issue queue and its project namespace -- reopening the issue]
Thanks!
-Bronius
Comment #4
texas-bronius commented(padding with some SEO in the title, even though it's more specific that the original author had requested and setting status back to Active)
Comment #5
a_thakur commentedHey Murz,
The code in comment #2 does not work for me. I suspect the line die(print iconv('UTF-8','CP1251',$csv)); is causing problem.
Comment #6
murza_thakur, this is not good code for use, this is only example how I solve this issue for only my site, I not recommend to use it on other sites. String
does codepage converting for Cyrillic language, so if you don't need this, you can use
Comment #7
kenorb commentedThese are probably needed to accomplish this feature:
#1548790: Adding view related information in the context of an action
#1902104: Allow batching to be skipped
Comment #8
kenorb commentedIgnore this one.
Comment #9
kenorb commentedAttached initial patch.
Tested with the following patch:
#1902104: Allow batching to be skipped
and option to disable batch process.
Comment #11
kenorb commentedKnown problems:
- it has problem exporting profile data
- could not work without #1902104: Allow batching to be skipped
Comment #12
kenorb commentedThis version is with entity dependency.
Comment #14
kenorb commentedIgnore this one.
Comment #15
kenorb commentedBetter, simpler patch which uses views_data_export handler.
To make it working, new display for views_data_export should be created.
It still requires 'Don't use batch/queue' option after applying #1902104: Allow batching to be skipped patch, otherwise it has some problems. Not sure how to workaround them.
In case of some issues:
- make sure that you've set 'Provide as file' in Format Settings,
- test with 'Attach to' to None
Comment #16
bojanz commentedThere is no reason why such an action couldn't work with batching.
Also, VBO itself depends on Entity API.
Comment #17
kenorb commented@bojanz:
When using in batch, it generates the error like:
, so basically it's dumping the CSV content.
Also what I noticed, is that the export action has some problems when View is embedded in Panel. But it could be some specific case.
The other thing is, that the export works for all the rows, despite of the user selection. Not sure how to change it.
Comment #18
Adon Irani commented#15: vbo-csv-export-1436726.patch queued for re-testing.
Comment #19
kenorb commentedThe other issue with CSV export is, that it doesn't export selected rows.
As workaround, it can be solved by creating 'Pass ids as arguments to a page' action with URL to the view data export page.
Related:
#1784156: Only first page of view results 'rows' passed to action on VBO execution
#1477760: Provide a way to get all ids of a row
#1180538: Pass the selected views row(s) to the action
Comment #20
chi commented15: vbo-csv-export-1436726.patch queued for re-testing.
Comment #21
ndewhurstHere's a follow-up to @kenorb's work that's functioning well for me. The underlying idea is unchanged (look for a views_data_export display in the same view, and execute that to generate the CSV).
Notes:
There may be some other assumptions or use cases I'm glossing over. Hopefully this is useful to others as well!
Comment #22
ndewhurstAnother thought: in the query alter, we could probably replace existing conditions with the entity ID condition rather than just adding it. We know that the entities with those IDs already satisfied the other view conditions, by virtue of the fact that they appeared in the VBO view and were selectable. (Right?) Presumably that could be a bit more efficient.
Comment #24
maxplus commentedHi ndewhurst,
your patch from #21 works for me.
As described in #52 https://www.drupal.org/node/1875456, I would like to find a more generic solution where I could combine several rules actions together (including the csv export of the selected items)
Thanks already for the work that is done
Comment #25
kenorb commentedComment #26
joelpittetRTBC++ I've been using this for some time now too.
Comment #27
djpable commented#21 works fine, but it would be awesome if you could add the possibility to add multiple actions for multiple views_data_export displays
Comment #28
jgullstr commentedAggregated actions limit (by memory) the amount of entities that can be exported, as all selected entities will be loaded on a single request. Ideally, there should be an option to only pass entity ids to the action, but this does not (to my knowledge) exist. Hence, using aggregate in #21 restricts the possible use cases.
Provided patch provides a workaround without aggregate. I also moved selecting display id to a VBO setting.
Comment #29
joelpittet@jgullstr could you post an interdiff between your patch and the previous one?
@see https://www.drupal.org/documentation/git/interdiff
Comment #30
jgullstr commentedInterdiff attached.
Explained:
I have only tested this on batched exports. An added benefit to this approach is that you will see the progress while entities are being loaded.
Comment #31
joelpittet@jgullstr thank you for the explanation also:)
Comment #32
den tweed commentedUsed patch #28 to make a VBO button for export, works good. Only problem I found is that the file downloads but the batch progress bar keeps on spinning, no redirect to the original page/view
Comment #33
jgullstr commentedThe additional argument added to the view by this patch is generating notices.
Comment #34
poindexterous commentedI am getting the same notices as above but it doesn't seem to effect the export.
Comment #35
djpable commented#28 is configurable and return to the view page, but it does not download anything for me :-(
I still have to use using #21 here.
Comment #36
retiredpro commented#28 worked for me. After patching the module I had to clear my site cache before I could see the new VBO option to export to CSV. The only thing that is strange is the operation confirm page does not display a name for any of the items that I have selected.
Here is my current setup.
My view pulls Ubercart Order entity if that matters.
Comment #37
graber commentedHi all, didn't notice this issue earlier and developed a module. You can check the code and maybe integrate the solution to views_data_export so we have all the functionality in one module. On the other hand no point having 5 display options and a few more actions to achieve 1 simple goal sometimes.. Anyway, take a look.
https://www.drupal.org/project/vbo_export
Comment #38
joel_osc commentedI am also seeing the issue where the CSV file downloads fine and contains the correct information, however the batch job does not return to the original page/view. Disabling batch mode works but this brings in some scaling concerns.
Comment #39
Jorrit commentedMe too, I think this makes patch #28 unacceptable at this point. The only solution, I think, is to save the entity ids in a SESSION variable somewhere, redirect back to the view and initiate the download from there. This is much more complicated.
This happens because
$argsmay only contain strings and this patch adds an array. This can be fixed byimplode()'ing the array before putting it in$argsandexpode()'ing it when changing it to a where condition.I want to update the patch to change this, but at this point, I rather use patch #21 than #28.
Comment #40
Jorrit commentedThis is an updated version of patch 21 to prevent this notice:
Comment #41
kenorb commentedComment #42
capysara commentedI'm not getting the expected results with #40, but I have a really specific use case (panel panes and facetapi, e.g.) so my issues may not be helpful here.
However, one thing I noticed is that the VBO action downloads more than just CSV, so the action "Export to csv" is misleading. Maybe "Export via Views Data Export" or "Views Data Export"?
Comment #43
steven jones commentedSorry for the lack of attention to your issue, please accept my apologies.
Drupal 7 is going to be end-of-life'd by the community in approximately 1 month.
As such, I am closing all non-critical looking, non-PHP compatibility issues for Views Data Export to tidy up the issue queues and reduce the noise. You can read about this on #3492246: Close down Drupal 7 issues.
If you feel like this issue has been closed by mistake, please do comment about re-opening it.
If you feel like the ticket is still relevant for the 8.x-1.x version of the module, then please search for a duplicate issue first, and if there really isn't one (and you've looked properly) then change the version on the ticket and re-open.
Thanks to everyone involved in this issue: for reporting it, and moving it along, it is truly appreciated.
The Drupal community wouldn't be what it is today without your involvement and effort, so I'm sorry that we couldn't get this issue resolved. Hopefully we'll work together in a future issue though, and get that one resolved :)