Drupal's poll results are output as a unique string divide in more text lines, one for hit with three information fields: choice, votes number, percentage.
Would it be better to tag the results output in a definition list?
I managed to modify the output string just using Php in poll-results.tpl.php, which can be overridden: I changed print $results; with two blocks:

$risultati=str_replace("(", " [", $results);
$risultanze=str_replace(")", "]  ", $risultati);
$voti = str_replace("\r\n\r\n", "", $risultanze);
$esiti=explode("  ", $voti, -1);
$sections=array_chunk($esiti, 3);
print "<dl>\n";
foreach ($sections as $section) {
    print "<dt>$section[0]</dt>\n";
        print "<dd>" . $section[1]. "</dd>\n";
        print "<dd>" . $section[2]. "</dd>\n";
}
print "</dl>\n";

It seems to work.
I hpe it may be useful.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mgifford’s picture

Component: postgresql database » poll.module
Issue tags: +semantic markup

Not sure about the approach (and it would have to be with English variables), but do like the result.

What are the possible performance issues? There's no need to use extra HTML elements I assume.

webchick’s picture

Version: 7.0 » 8.x-dev

We can't make changes to core modules' output in 7.x, but we can look at it for 8.x.

francesco_sardegna’s picture

For the next suggestion (I hope there will be) I shall use English variables, even if for example.
Perhaps this code may help understand the meaning of the poll results giving each data the right collocation (dt is the answer and dd are the number of votes and the percentage) and the right rythm.
I would not know how to tag it without using extra Html elements.

mgifford’s picture

That's great. It's also easier to refer to a patch. Not sure if you've looked into this but http://drupal.org/node/707484

amateescu’s picture

Assigned: francesco_sardegna » Unassigned
Category: task » feature
Status: Active » Needs review
FileSize
98.18 KB
1.52 KB

How about something like the attached patch? It gives us this nice structure:

poll-definition-list.jpg

I didn't include any screenshots because there is absolutely no change :)

Status: Needs review » Needs work

The last submitted patch, 1315616.patch, failed testing.

amateescu’s picture

Status: Needs work » Needs review
FileSize
2.22 KB

Hmpf.

mgifford’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
138.74 KB

A simple but effective patch. HTML output is:

    <dl>
    <dt class="choice-title">yes</dt>
<dd class="choice-result"><div class="bar" data-max="9" data-value="5">  <div style="width: 56%;" class="foreground"></div></div>
<div class="percent">56% (5 votes)</div></dd>
<dt class="choice-title">no</dt>
<dd class="choice-result"><div class="bar" data-max="9" data-value="3">  <div style="width: 33%;" class="foreground"></div></div>

<div class="percent">33% (3 votes)</div></dd>
<dt class="choice-title">I prefer 456</dt>
<dd class="choice-result"><div class="bar" data-max="9">  <div style="width: 0%;" class="foreground"></div></div>
<div class="percent">0% (0 votes)</div></dd>
<dt class="choice-title">don&#039;t care</dt>
<dd class="choice-result"><div class="bar" data-max="9" data-value="1">  <div style="width: 11%;" class="foreground"></div></div>
<div class="percent">11% (1 vote)</div></dd>
  </dl>

Patch applies nicely & looks just fine.

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 8.x. Thanks.

sun’s picture

Status: Fixed » Needs work
+++ b/core/modules/poll/poll.module
@@ -823,7 +823,8 @@ function poll_view_results($node, $view_mode, $block = FALSE) {
+      '#prefix' => '<dt class="choice-title">' . check_plain($choice['chtext']) . '</dt>' . PHP_EOL . '<dd class="choice-result">',
+      '#suffix' => '</dd>' . PHP_EOL,

We use "\n" everywhere else throughout Drupal core for consistency.

amateescu’s picture

Status: Needs work » Needs review
FileSize
811 bytes

Sorry for that :/

Status: Needs review » Needs work

The last submitted patch, 1315616-11.patch, failed testing.

amateescu’s picture

FileSize
801 bytes

Or even with less chars :) I'll set to needs review when HEAD gets unbroken.

sun’s picture

Status: Needs work » Reviewed & tested by the community
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed the follow-up, thanks!

Automatically closed -- issue fixed for 2 weeks with no activity.