hi all!
i've been searching for the last hour, and havent been able to find anything too similar to this, so i figured i should ask for some help.
i'm building a band website for a friend. one of the content types is called "record," for each record they put out. now, bands release albums in different formats, so one of the fields i created was a multi value check box called "format." the available "formats" are CD, VINYL, CASSETTE (yes, some labels still put out cassettes!) and digital downloads.
in Views, i created a field view that lists the available format.
this is what it looks like:
CD
VINYL
CASSETTE
but this is what i'd LIKE it to look like:
CD/VINYL/CASSETTE
so to sum up, i'd like to group multiple value fields into a single row, and insert slashes or comma's between the values if there is more than 1.
Comments
Comment #1
markus_petrux commentedI think you can override the function theme_content_view_multiple_field() in your theme's template.php. This funcion is located at the bottom of cck/includes/views/content.views.inc
Here you can check for the field name, and generate a different layout when multiple items are involved for a particular field.
Comment #2
hunterchristy commentedthanks! i got them all on the same line, but now it looks like
CDVINYLCASSETTE
how would i go about intelligently inserting slashes?
Comment #3
markus_petrux commentedTry with something like this:
Comment #4
hunterchristy commentedso i got this back:
warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'theme_content_view_multiple_field' was given in C:\wamp\www\library\includes\theme.inc on line 617.
Comment #5
hunterchristy commenteda-ha! got it! thanks so much for your help.
though i AM curious as to what this means and what i'm missing out on by it not working in this function i cobbled together:
" // If this is not my tuned field, then use original theme function directly."
Comment #6
gafir777 commentedI don't know if you guys noticed, but the $items array is still outputting the selected allowed values wrapped around a span:
I just want to get the raw value (the raw text) without the span around it. I'm not sure how to proceed for that.
Thanks
Comment #7
gafir777 commentedWell I have added inside the foreach loop
It's not great but it works. I'm still trying to find a way to have the raw text inside the $items array rather than this html with span. Any idea?
Comment #8
markus_petrux commentedRe: Any idea?
Yes, here's where you would have to use a different formatter for the field. Note that you're playing here with a theme function that simply contatenates items for multiple value fields, but the individual items are formatted with the options selected for the field in the view settings form for that field.
Comment #9
gafir777 commentedHi Markus, THanks for your answer! So if I were to output it without the span, where do I change the option for the field? Is this directly from the Views interface? Or is it something I should be doing in the views template php for that particular field?
Thanks!
Comment #10
gafir777 commentedInside the settings for the field inside my view, i've changed from Format: default to Format: plain text
But it stills outputs the span.
Also tried to changed the display field settings for the content type, although I don't think it changes anything to the view...
Comment #11
markus_petrux commentedNot sure which fields it is, but each item is being formatted as per the format settings defined for the field in the view itself.
Now, find out the script used by this field to render the output for the formatter you have selected. You should find a theme function that you should be able to override from your theme.
That's a method. Another method would be that you can create a new formatter for this field. See CCK Formatters module for an example. Once you extend a field with a new formatter you can render it without any further HTML tags, and you will be able to choose this formatter from your view, or from the "Display fields" screen, etc.
Comment #12
gafir777 commentedHi markus !
Thanks for the advice. I think creating a new formatter is the way to go.
I'll keep you updated.
Thanks!
Comment #14
jweedman commentedThanks very much for this code. You saved me alot of time... and probably some hair from being pulled out. I would think Views could incorporate some sort of separator for multiple value fields.
Anyway, Thanks for sharing your solution... it really helped.
-jweedman
Comment #15
my-family commented#3 code works well, but not with Ajax and exposed filters (with ajax in view, after applying the filter, the output seems as if the function was not used at all). Any ideas?
Anyway, thank you very much for the code!
Comment #16
syakely commentedI like it. One modification would be to call out the field you want to alter, so all other fields get rendered the stock way.
Comment #17
redhatmatt commentedAnd no spelling errors either! Great Job Shane!
Comment #18
matsjacobsson commentedThis works great for what I need..
But how do you do if you want it to affect the field even if it only contains one item? Thanks! /Mats
Found it! : http://drupal.org/node/472996#comment-3770168
Comment #19
matsjacobsson commentedIs there any way to limit it to a page display instead of field? /Mats
Comment #20
tarzadon commentedThis is exactly what I was looking for. Thanks!
Comment #21
squarecandy commentedThanks - perfect.
Comment #22
baisongI had the same problem, creating a downloadable CSV feed view for a view, all my data was being concatenated with no separator -- I believe if it wasn't a plain-text view handler, there would be markup to separate the values.
As a solution, I used a customfield PHP snippet to generate arrays and implode them in the view. Probably slow for production sites, but for data extraction, it seemed sufficiently fast. Just install the customfield module, add a customfield PHP snippet (make sure you have permission to evaluate the PHP input format) and then paste these snippets in (along with the unseparated multivalued fields, exclude to hide them) to generate the separated list.
This is for text/number values
This is for node references (I needed the title from the node id (NID)
Comment #23
pandapowder commentedIs there any way to do this in drupal 7?
Thanks
Comment #24
yan commentedCan't believe that it's still such a hassle to simply have some field values in one row...