…instead of to the node page - though if someone votes from that page, it will still work. I'm using Plus1 in a case where I'm using a view to list several nodes on one page, from which users can vote, and we want them to go back to that same view page, not to the node's page.

CommentFileSizeAuthor
plus1-referer.patch466 bytesGarrett Albright
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

NancyDru’s picture

Looks good to me.

voxpelli’s picture

Status: Needs review » Needs work

A fallback is needed if the referer isn't set since we can't rely on the referer always being there?

NancyDru’s picture

Just a thought: How about something like

  drupal_goto($_GET['q'], drupal_query_string_encode($_GET, array('q')));

Shouldn't that work in all cases?

NancyDru’s picture

Actually, my suggestion does not work because the button goes to /plus1/vote. However, would that not ensure that a referer is set?

voxpelli’s picture

I don't think referers can be relied on - why not use Drupal's destination system instead?

NancyDru’s picture

How about

      drupal_set_message(t('Thank you for your vote.'));
      
      $path = "node/$nid";
      if (isset($_REQUEST['destination'])) {
        $path = $_REQUEST['destination'];
      }
 
      drupal_goto($path);

and

      $output_content .= '<form class="' . $vote_class . '" action="'
        . url("plus1/vote/$node->nid",
          array('query' => 'token=' . drupal_get_token($node->nid) . '&' . drupal_get_destination()))
        . '" method="post"><div>';
      $output_content .= '<button type="submit"><span>' . t($vote_text) . '</span></button>';
      $output_content .= '</div></form>';

I'm not sure, but I think the query string should use drupal_urlencode().

voxpelli’s picture

The drupal_goto('node/'. $nid) doesn't need to be changed - we only need to add the destination to the url. We could do that as an extension of the patch in #322735: Vote link is executed by search engines?

NancyDru’s picture

Too fast; we cross-posted.

NancyDru’s picture

Status: Needs work » Patch (to be ported)
NancyDru’s picture

Status: Patch (to be ported) » Fixed

Committed to 6.x-2.x-dev.

Status: Fixed » Closed (fixed)

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