Hello! I started using advpoll.

I would like to integrate advpoll into panels, i.e. when calling a node of the type advpoll, panels should take care of the presentation through pages.

Until now I managed this by using selection rules and choosing here the node type I want to display through pages.

But advpoll has also additional views, like results. These are not catched by the pages selection rules.

How can I, using for instance the selection rules, catch all the advpoll content to display it through pages?

Thanks

CommentFileSizeAuthor
#4 copri_content_type.inc_.txt4.52 KBtchase
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

iadegesso’s picture

Same need. Is there a way to format an advanced poll with panels?

pavlosdan’s picture

I needed to display advpoll content with Panels as well but the fields being made available in "Node" were not displaying the full Poll widget with the Ajax functionality etc.

What I did to make the Poll show up and work in panels was:

In a custom module you can define a ctools content plugin as described here: http://internetdevels.com/blog/ctools-content-type. Thanks @brunodbo for the link and idea.

Then in your plugin file enter the following:

/**
 * Plugins are described by creating a $plugin array which will be used
 * by the system that includes this file.
 */
$plugin = array(
  'single' => TRUE,
  'title' => t('Advanced Poll'),
  'content_types' => 'advpoll',
  'icon' => 'icon_node.png',
  'description' => t('The poll associated with the node.'),
  'required context' => new ctools_context_required(t('Node'), 'node'),
  'render callback' => 'advpoll_render',
  'edit form' => 'advpoll_edit_form',
  'category' => t('Node'), 
  'defaults' => array(
    'link' => TRUE,
  ),
);

/**
 * Render the custom content type.
 * Code stolen and adapted from hook_node_view of advpoll.module
 */
function advpoll_render($subtype, $conf, $panel_args, $context) {
  if (empty($context) || empty($context->data)) {
    return;
  }

  // Get a shortcut to the node.
  $node = $context->data;

  // Load information about the node type.
  $type = node_type_get_type($node);

  // Build the content type block.
  $block = new stdClass();
  $block->title   = $type->title_label;
  $block->delta   = $node->nid;

  $data = advpoll_get_data($node);
  if ($data->behavior == 'approval' || $data->behavior == 'pool') {
    drupal_add_css(drupal_get_path('module', 'advpoll') . '/css/advpoll.css', array('group' => CSS_DEFAULT, 'every_page' => TRUE));
// check for eligibility to vote
    if (advpoll_user_eligibility($node)) {
// print out voting form
      $voteform = drupal_get_form('advpoll_choice_form', $node);
      $block->content['advpoll_choice'] = array(0 => $voteform, '#weight' => 1);
    } else {
// get user's votes if they're logged in and if voting is normal
      $votes = array();
      if ($data->mode == 'normal') {
        $votes = advpoll_get_user_votes($node->nid);
      }

      $results = advpoll_display_results($node->nid, $data);
      $block->content['advpoll_choice'] = array('#markup' => $results, '#weight' => 1);
    }
  }

  return $block;
}

/**
 * Returns an edit form for custom type settings.
 */
function advpoll_edit_form($form, &$form_state) {
  return $form;
}

/**
 * Submit handler for the custom type settings form.
 */
function advpoll_edit_form_submit($form, &$form_state) {
  // Copy everything from our defaults.
  foreach (array_keys($form_state['plugin']['defaults']) as $key) {
    $form_state['conf'][$key] = $form_state['values'][$key];
  }
}

/**
 * Returns the administrative title for a type.
 */
function advpoll_admin_title($subtype, $conf, $context) {
  return t('"@s" title', array('@s' => $context->identifier));
}

The above will make an advpoll plugin available in the Node category of Panels. Adding that on your Panel overriden node will make the AdvPoll show up in your node. The code for the render part of this to make the poll appear was taken and adapted from hook_node_view of advpoll.module.

tchase’s picture

This worked great for me for "approval" voting behavior, but it does not work for the ranking poll behaviors. I'm not a php programmer (had a colleague make the module described above for me), so I apologize if the solution is obvious. Is there a tweak to the above for ranking polls I can do, or is this much more complicated? Thanks.

tchase’s picture

Issue summary: View changes
FileSize
4.52 KB

Attached is a solution to #3 following the same procedure in #2 by incorporating the advpoll_ranking_node_view code from the advpoll_ranking.module into the same ctools-content-type outlined above.

tripper54’s picture

Category: Support request » Feature request

Rolling this into the respective modules makes sense.

Patches welcome!

tripper54’s picture

Title: How to integrate advpoll into panels » Offer panels integration