Here is a description of this bug:
I wanted the captions of each slide to be the title of the node followed by "uploaded by username." This kind of thing is pretty common to do in Views by rewriting the output of a field. My setup was the following (everything not mentioned was done according to the documentation):
Added the proper image field
Added a field User: Name
Added a field Node: Title
In Node: Title field I checked "Rewrite the output of this field" and entered the following: [title] - uploaded by [name]
Usually you would "exclude" the User: Name field but in this case it isn't shown either way and makes no difference to the behavior I'm observing.
In Row Style I set the photo field to be the photo and the title field to be the title.
I have 2 nodes with the following actual data:
Image 1 with title "Title 1" which was created by user X
Image 2 with title "Title 2" which was created by user Y
From the view my slides appear like so:
Image 1 appears with the caption "Title 1 - uploaded by X"
Image 2 appears with the caption "Title 2 - uploaded by X"
Notice that it's listing X as the creator of both.
If I change the view to be a table view, then my rewritten titles show properly:
"Title 1 - uploaded by X"
"Title 2 - uploaded by Y"
Even with other fields (created date, path, etc) the first node's data is always used for replacement data in the titles of all the other slides. This behavior only occurs when using views_nivo_slider as the output method.
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | views_nivo_slider-803604.patch | 2.39 KB | pedrofaria |
| #10 | views_nivo_slider-803604.patch | 1.93 KB | msielski |
Comments
Comment #1
TomMynd commentedHi,
I also stumbled upon the same error.
Any ideas?
Best regards, Tom
Comment #2
pedrofaria commentedHello guys,
I made some tests and add managed to make views nivo slider module work with rewrite output option too.
i will commit to cvs now and a new dev release will be available to download at this night...
Please, try and send me a feedback.
thanks
Comment #3
pedrofaria commentedComment #4
TomMynd commentedHi,
I had to time to test the dev-release, but the problem stays the same. You changed the output to strip all html-tags, but that did not fix the issue and I think this will be not a good default way for the rewritten output, because people will add HTML to the output to structure the caption. Besides that all the HTML will go into the p-container with style "display:block" and that will result in unvalidated html. But this is another issue and should be discussed elsewhere.
So... I made a content type with image, title and subtitle and want to display both titles inside the caption. I build a view and rewrite the output of the title to show the title and the subtitle. It looks something like this:
I've added no HTML because currently it will be stripped (as mentioned above).
When I look at the resulting page the image und the title are shown as espected, but the subtitle stays the same on every slide. The subtitle that is shown is the subtitle of the last slide inside the views result so maybe there is something wrong with the rewrite-handling.
When I change the View-Style to "Unformatted" the result of the display is correct. There is the image and the combined title and subtitle for the slide.
Maybe I will have some time this afternoon, to dig a little deeper.
have fun,
bye!tom
Comment #5
TomMynd commentedI tested it with Views Rotator. This will get the rewritten output of the title-field as espected and correct.
Comment #6
TomMynd commentedI've looked a little bit inside the views_nivo_slider.module and I think it has something to do with the rendering call in line 76:
A dpr() of $vars['row'] showing up the correct data for every item.
Currently I'm unable to find the code that will get executed when the "->theme()" part of this is called, but I would be thankful, if someone can enlight me! :-)
Best regards, Tom
Comment #7
msielskiJust want to comment that I was able to test the dev release (May-20) and the release does not fix this problem.
Also, as TomMynd pointed out, now strip_tags is enabled which is not a great move as previously you could stuff HTML in there and it worked well.
I can also see that $vars['row'] has the proper data, but what comes back out of
$view->field[$options['title_field']]->theme($vars['row'])and gets assigned to $title is incorrect, or at least doesn't get replacements applied.I'm still trying to trace through all the views code - there's a lot of it.
Thanks for addressing this issue pedrofaria and TomMynd.
Comment #8
pedrofaria commentedHi all,
i managed to reproduce the error and i am debugging views module to find the problem... but at this moment, no progress...
if some one can help me, i will appreciate...
let's back to the big views module source code...
Comment #9
msielskiI've been digging in the views code (and I'll admit I haven't been deep into views.module in a while) but I have a feeling the problem is due to rendering the fields from the preprocess function.
The view itself is rendering these fields once. The template_preprocess_views_nivo_slider_view_nivo_sliderfields in views_nivo_slider.module is rendering them again by calling theme() on the field handler. The rendering process calls views_handler_field::advanced_render() each time, and while I definitely am far from understanding advanced_render it appears to keep track of its previous value. I'd guess that the double rendering of the fields is confusing advanced_render.
Just a hunch at the moment. There has got to be a way to build the output of each row without rendering the fields an extra time.
Tom, for your info the call to theme() is a member function of a views_handler_field object defined in views/handlers/views_handler_field.inc. theme() then calls theme_functions() to get a list of possible theme overrides, but if like me you don't have any then control will go to the least specific one: views_view_field() defined in views/theme/theme.inc. This in turn will finally call advanced_render for whichever field handler is involved, so we end up at views_handler_field::advanced_render() in views/views_handler_field.inc. From some dpm statements in advanced_render it looks like that's where the mixup is happening, but I'm still struggling with understanding the code.
Comment #10
msielskiI have a patch against 6.x-1.x-dev which fixes the issue, however this may not be acceptable because it removes a few adjustments. Maybe we can all find a way to get the removed code working again.
I stood by what I thought in #9: the problem seemed to be from calling theme() on the fields a second time, in the preprocess function. I found that the already rendered values are available in $view->style_plugin->rendered_fields so that this code:
can become:
It uses $id, which is available via $vars['id']. "rendered_fields" contains the already rendered HTML. The same change can be made to the two other fields, as done in the attached patch.
The downside is that now that we're not calling theme() again, any setting changes made to the field will not be observed. That includes:
for the thumbnails, and:
for the title, and finally:
for link. I've removed these with the patch as they do nothing now, but they probably should be added again somewhere appropriate.
If there is anywhere in a views plugin that we can alter the view before it is rendered, then this code needs to go there.
If that is impossible, then it's required that users of this module: 1, choose the Format "Path to file" for the image field, 2, do not make the title a link, and 3, use plain format for link fields. I think these are reasonable requests but it would be best to have the view plugin enforce these settings like it had been.
I hope I'm not down the wrong path here. It seems like the right way to fix this, but I am learning this as I go. Thoughts?
Comment #11
TomMynd commentedHi,
thank you for your work and for the explanation. After submitting the patch against the dev-version and changing the Imagefield to the path of the image ("Path to file") it worked like a charm.
I would also vote to remove the styling from this module, because most of the styling could be done throught the "normal" field-setup inside the view.
I will play around with some settings to get the result I had before. I hardcoded some styling stuff inside the views_nivo_slider.module to get around the error.
Comment #12
pedrofaria commentedHello guys,
Thank for your time spent at this module... i really appreciate it!
Your patch could be a great solution... but we have to improve the documentation of this module to prevent support request or think an other solution... any suggestions?
Any way, i has opened an issue at views project asking for a better explanation...
#805986: Rewrite output is repeating values for User: name field
let's wait for a reply to take any decision... ok?
Comment #13
TomMynd commentedThat's ok for me.
Best regards, Tom
Comment #14
msielskiI agree, let's see if we can get some feedback first. I would like to prevent the users from making mistakes while setting up this plugin -- I can only imagine that people would use the wrong formats frequently.
@pedrofaria, I hope someone from the Views issue you posted can suggest how to alter the view's settings before the first render. Keeping my fingers crossed!
@TomMynd, thanks for confirming the patch worked for you.
Comment #15
pedrofaria commentedHello guys,
Great news... :)
i have build a patch with the fix proposed by @dereine at #805986: Rewrite output is repeating values for User: name field.
pls, test and send me a feedback...
thanks.
Comment #16
TomMynd commentedHi,
applied the patch and it worked nearly as expected. I think you should not set any hardcoded settings for the title inside the module-code as mentioned in #4 and #7 by MattheusX and me.
If you remove Line 72-76 of the patched views_nivo_slider.module this will be erased.
These settings can be done inside the view-configuration itself.
When I have some time I can write up a little tutorial how to rewrite the output of the title field to get more content inside the nivo-slider-description-div. This would also a or the solution for #779716: Body Field .
Thanks for your work and best regards, Tom
Comment #17
pedrofaria commentedHello Tom,
You have to consider this FIXED params to prevent any HTML error. The title text as an image html tag parameter (Eg.
<img src="..." title="<?php print $title ?>" />)...I really don't know if do this could be a good idea.
Comment #18
TomMynd commentedHi,
ok... I will try to explain what I'm doing and how the filtering of the title will break it:
I setup a content type (name it frontsplash) with an image, title, subtitle and a nodereference to an article. The slider is shown on the frontpage of the site and a contentmanager can setup teasers to articles with this content type to promote them to the frontpage and link directly to the given article.
The slider should display not only the image (thats clear) and the title. It should also show the subtitle and a link to the article.
I setup a view to display nodes of type "frontsplash" and the fields image, title, subtitle and nid (relationship with article). In the "Row style options" I choose the image for the "Image Field" and the title for the "Title" field. The "Link Field" is set to none. That's straight forward and works out of the box.
To get the subtitle and the link to the appropiate article I configure the field "Title" to "Rewrite this output of this field". I can now add content from the other available fields to the textfield for the rewrite option. Currently the content looks like this:
The [nid] is also a rewritten output to output the link to the article.
When I use the patched dev-version of views_nivo_slider.module all the html-tags will be stripped and I will have no chance to style the output any further. When I comment the mentioned lines in #16 the html-tags will be inserted and with some css-magic the whole box can be styled.
One thing that is left to discuss is what you mentioned that this content will be included inside the title- and alt-tag of the img-tag. That is really a problem and should be discussed first and how we can get around that. There is also a p-tag around the Title-field that will result in html-errors when you include h2- or h3-tags or other tags that are forbidden inside.
Best regards, Tom
Comment #19
pedrofaria commentedI guess you didn't understand me...
If i release html at title field, look what can help... using your exemple...
This is right?
I know that using title parameter is veeeeeeeeeery limited and there is a issue at nivo slider library project page to implement it.
http://github.com/gilbitron/Nivo-Slider/issues#issue/5
If some day gilbtron implement it, i can put your request on code easily.
Any doubt?
ps.: at #17, i didn't edit code correctly.. please, go back and see what view nivo slider do.
Pedro Faria
Comment #20
TomMynd commentedHi,
as writing my comment some things started to clear up and I see the reason why you add the stripping to the title tag.
Currently I think that this is a big annoyance of nivo slider - not your fault!! But this will lead to the point that nivo slider can not be used in most of the use cases for sliders or say advanced usage of such sliders.
I will think and dig a little bit about this situation and maybe I will get some more insights into this issue.
So as your patch did what it should do, I will change the status to "reviewed" and I think you could fire up a new dev-release.
Best regards, Tom
Comment #21
pedrofaria commentedCommited!
Tom, i know... you can post a comment at nivo slider library project page requesting this feature... this is the only way...
I need to thank you and MatteusX for the spent time on this module!
Regards,
Pedro Faria
Comment #22
pedrofaria commented