The function poll_view_results (API documentation: "Generates a graphical representation of the results of a poll") does not contain any html code, but I think it should be implemented as a theme function, so it can be overridden. Right now, I cannot control the output of the poll results as much as I'd like to. Overriding poll_view_results would allow me to add 'presentation logic' such as ordering the results from high to low, or scaling the width of the result bars so that the widest bar is always 100px wide (regardless of the percentage it represents).
I'm not experienced in module development; Would this be as easy as renaming poll_view_results to theme_poll_view_results and changing the references to poll_view_results accordingly?
Comments
Comment #1
marcvangendIf anyone's interested: I wrote some lines of Javascript (jQuery) to achieve the scaling of the graph bars (as mentioned in my post above). I'd still prefer to have this in php, but this works.
This example illustrates perfectly why poll_view_results should be a theme function: you can't control the output completely if you can't process all values first (in this case: search the max value and calculate the scale factor).
Comment #2
sunMakes totally sense. As poll module is quite self-contained and there are almost no contrib modules extending on it, I guess this can still be done for D7.
Can you roll a patch? Ideally, most of the preparation and hard logic should be moved into a preprocess function, so the (wrapping) theme function is easily alterable for themers.
Comment #3
marcvangendWow, this issue is old... I'm surprised that you dug it up, Daniel :-)
Fortunately I'm much more experienced in module development now, so if time permits (poll module is not on top of my priority list) I'll roll a patch.
Comment #4
amateescu commentedWe should definitely do this in D8.
Comment #5
maxmendez commentedThis issue has been resolved.
Comment #6
marcvangend@MaxMendez can you elaborate? I see there have been some changes, in #1229442: Convert poll tpls and markup to HTML5 for instance, and looking at the code it seems to solve the specific use case from #1.
However, this issue is not merely about scaling the largest bar to 100%. This issue is about giving the themer control over the calculations that are made before the values are passed on to the theme function or template. As far as I can see, that is still not possible.
Comment #7
sunAt minimum, the poll_view_results() should return a render array instead of calling theme() directly.
Second, no premature drupal_render(). This means the poll_results theme function/template needs to deal with a render array in $results instead.
Lastly, @marcvangend should clarify which variables (and thus calculations) in poll_view_results() he wants to adjust. Those variables (and affected calculations) need to happen in a template_preprocess_poll_results() preprocessor instead then.
That clarification and this (my) comment should also be copied into the issue summary.
Comment #8
alexpottPoll is no longer part of core
Comment #9
berdirI don't think there's any point in keeping this. polls are an entity now and use a view builder + form + template to display results, there should be plenty of ways to customize the output. If not, then we can open a new, more specific issue.