Basically if my CCK type has a select field where multiple values are possible, those values swill appear as :
"Value1Value2Value3" in the exported file.
They could be "Value1, Value2, Value 3" or "Value1 Value2 Value3"
Basically if my CCK type has a select field where multiple values are possible, those values swill appear as :
"Value1Value2Value3" in the exported file.
They could be "Value1, Value2, Value 3" or "Value1 Value2 Value3"
Comments
Comment #1
marco.giaco commentedI've been facing this problem too, the simplest solution I've found is to add a custom formatter (within a module) and to select this inside field views field format. It would be nice to integrate this inside views_bonus with the ability to choose the preferred separator (now its hardcoded).
/**
* Implementation of hook_theme().
*/
function my_module_theme() {
return array(
'my_module_formatter_separator' => array(
'arguments' => array('element' => NULL),
//'function' => 'theme_my_module_formatter_separator',
),
);
}
/**
* Implementation of hook_field_formatter_info().
*/
function my_module_field_formatter_info() {
return array(
'separator' => array(
'label' => t('Comma separated multiple fields'),
'field types' => array('text'),
'multiple values' => CONTENT_HANDLE_MODULE,
),
);
}
function theme_my_module_formatter_separator($element) {
$values = array();
// Cycle through the file elements
foreach (element_children($element) as $key) {
if (isset($element[$key]['#item']['safe'])) {
$values[] = $element[$key]['#item']['safe'];
}
}
if (empty($values)) {
return;
}
return implode(', ',$values);
}
Comment #2
boabjohn commentedHere Here! (+1^10)
It's fairly odd: seems to be an oversight in the usecases for the CSV export. What is the solution to 1000 rows with up to 6 terms concatenated like this? No pattern replace possible...
JB
Comment #3
Sera commented/subscribe
The same error appears when I have a grouped field containing a userreference and a textfield. So my output looks within the CSV export like:
"userreference1userreference2textfield1textfield2"
I dont understand #1 fully. In which file do I have to insert what code snipet?
And yes, it would be cool to choose a separator for that isssue, even a break would be ok to receive
"userreference1
userreference2
textfield1
textfield2"
Best regards
Sera
Comment #4
dgastudio commented+1
Comment #5
liquid06 commented+1 If the multivalue fields could be delimited, it seems like this module could be used to move node content out of one Drupal installation and then node import could move it into another Drupal installation. Agree with #1 that the user should choose the separator through the interface - it might need to change based on the content of the field.
Comment #6
nicolas.tala commented+1
This module is really helpfull, but I didn't understand why my users multiples roles were correctly separated, with the separator I chose, and these cck fields were not.
I hope this problem wil be solved soon.
Thanks to all the contributors.
Comment #7
jtjones23 commented+1
Comment #8
c4marcus commentedThanks marco.giaco !
However, we were in need of using the separator on a multi select nodereference field. Below is my modified version of your example.
function my_module_theme() {
return array(
'my_module_formatter_separator' => array(
'arguments' => array('element' => NULL),
),
);
}
function my_module_field_formatter_info() {
return array(
'separator' => array(
'label' => t('Comma separated multiple fields'),
'field types' => array('text', 'nodereference'),
'multiple values' => CONTENT_HANDLE_MODULE,
),
);
}
function theme_my_module_formatter_separator($element) {
module_load_include('inc', 'Content', 'includes/content.crud');
$values = array();
// Cycle through the file elements
foreach (element_children($element) as $key) {
if (isset($element[$key]['#item']['safe'])) {
$settings = content_field_instance_read(array(field_name => $element['#field_name']));
if ($settings[0]['type'] == 'text')
$values[] = $element[$key]['#item']['safe'];
else if ($settings[0]['type'] == 'nodereference')
$values[] = $element[$key]['#item']['safe']['title'];
}
}
if (empty($values))
return;
return implode(', ',$values);
}
Comment #9
j d ess commentedsubscribe
Marco or grizzly, could you provide some elaboration for a noob on how/where/etc the code goes? Thanks!
Comment #10
nruest commentedI second j d ess - Marco or grizzly, could you provide some elaboration for a noob on how/where/etc the code goes?
I created a custom module based on grizzly's code and I'm not seeing and difference in the CSV export features at all. A bit more guidance would be great.
Thanks!
Comment #11
ayesh commented+1 - this problem still exists in 6.X 1.11 too(latest to the date).
I think we need to fix this asap.
Comment #12
clintthayer commentedAnd it looks like this is Drupal 7 base code? Not seeing a reference to hook_field_formatter_info for D6.
Comment #13
501cGeek commentedI have also encountered this problem, with the latest Drupal 6.20 and Views Bonus Pack 6.x-1.1. Also unclear about what to do with the above code.
As somewhat of a workaround, exporting to XML instead of CSV does separate the multiple entries, by adding HTML divs to separate multiple items in a field. You could potentially do a find and replace on the XML export to replace this HTML with commas. If the intended destination of this export is able to accept XML as input.
Comment #14
mdm commentedHi all,
nruest asked me to post my solution here. All I did was implement hook_preprocess_views_bonus_export_csv in my theme's template.php. Our multi-valued source field looks like this:
and was being output like this:
Which was obviously not what we wanted. My solution was:
The important lines here are:
...which you'll probably have to tweak for your own situation, and of course you should change "zen_ninesixty" in the function name to whatever theme you're using. The $vars['separator'] is hardcoded to a comma here because for whatever reason, this module was ignoring whatever I set in the views admin UI. Hope this helps!
Comment #15
ayesh commentedThis issue seems to be fixed in 6.11 release. I tried today with amazing success!
Comment #16
nruest commented@Ayesh what combination of views modules do you have - what are the versions? When I do an export with the 6.x-.1.1 release CCK fields with multiple values are not separated.
---
nvm - got it working now.
Comment #17
aaronbaumanthis issue persists to 1.x-dev
Comment #18
aaronbaumanNow that I think about it, however, I think this is primarily an issue with CCK.
CCK field handlers should provide a "separator" option when "group multiple" is selected.
I didn't find such an issue in the CCK queue after a quick look, but I'd be surprised if it has not been posted already.
Comment #19
Encarte commentedSubscribing
Comment #20
blauerberg commentedSubscribing
Comment #21
dwadson commentedI got around this by adding two instances of the field to my view, and used the "Show __ value(s)" and "starting from __" options in "Group multiple values" to put only one value in each field. Since my multi-select field could only have a maximum of 2 values, it was a simple way to split the values.
Comment #22
tobiberlinI did implement a module like in #1 - but my problem is that the CCK select box has key values like
Now when I activate the module just the keys are exported but not the names/ values. Can somebody help me? How do i get the values like "Option 1" shown in my CSV export instead of the key values?
Best,
Tobias
Comment #23
langworthy commentedHere's a first stab at a fix in CCK itself http://drupal.org/node/1829634#comment-6679170
Comment #24
neclimdul