The default poll runtime settings don't fit our needs. We need to have a time window with a specific start date and a specific end date. When it's too early the button and radio inputs will be hidden. I solved that by a simple hook_form_alter(). But when it's too late the results view should be displayed and I can't find out how.

All anonymous users.

I know I could hook_init() everybody to the node/%nid/results URL. Problem is, this URL gets unavailable when the user already voted. How does Drupal know if someone already voted? How can I call the clean URL alias of a node and ensure that always the results view will be displayed even when the poll settings still say the poll is open?


It's template_preprocess_node() to hook in :D

function MYTEMPLATE_preprocess_node(&$vars) {
  // check if we are in the right place
  if ($vars['type'] == 'poll') {
    if ( /* add other conditions here if you need to */ ) {
      // then unset the voting view first
      // and add the results view instead
      $node = node_load($vars['nid']);
      $vars['content']['poll_view_results'] = array('#markup' => poll_view_results($node, TRUE, FALSE));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.