Is there a way to print the widget in a panel?

I have been trying for a bit now and can't seem to find it.

These print the actual value but not the widget
print $node->vote_up_down;
print $node->vote_up_down{value];

Comments

jared.Homesavvi’s picture

Hey;

For one; I think you meant print $node->vote_up_down['#value']; for that second line there.

Also, one thing you can do is actually print the theming functions for these, so you would do something like;

 $output .= theme('vote_up_down_widget', $node->nid, $node->type);
 $output .= theme('vote_up_down_points', $node->nid, $node->type);

There is probably a better way to get around this issue, and I am not sure if I am doing this entirely correct, but if someone would please jump in and say something that would be great.

jase951’s picture

Doesn't seem to work in 6.x-2.x.

ron williams’s picture

Status: Active » Closed (duplicate)
socialnicheguru’s picture

Status: Closed (duplicate) » Active

But this is not solved for version 2. The other version just said revert back to version 1.
That is not a fix is it?

marvil07’s picture

Category: bug » support
marvil07’s picture

Status: Active » Closed (duplicate)

yep, duplicate of #544354: How to display voting widget by API for nodes?, there we should get a solution for 2.x

mradcliffe’s picture

Status: Closed (duplicate) » Needs review

I made a content_type plugin for vote up/down nodes. Are you interested in trying to integrate this into vud itself (along with respective tax. and comment contextual plugins)?

please re-duplicate if not interested or out of scope

/**
 * Plugin definition
 */
$plugin = array(
  'single' => TRUE,
  'title' => t('Node: Vote Up/Down'),
  'icon' => 'icon_vud.png',  //@todo
  'description' => t('The Vote Up/Down widget for a node.'),
  'render callback' => 'vudpane_node_render',
  'edit form' => 'vudpane_node_edit_form',
  'required context' => new ctools_context_required(t('Node'), 'node'),
  'category' => t('Node'),
  'defaults' => array(
    'override_title' => FALSE,
    'override_title_text' => '',
    'widget' => '',
  ),
);

/**
 * Implementation of render callback
 */
function vudpane_node_render($subtype, $conf, $args, $context) {
  if (isset($context->data)) {
    $node = drupal_clone($context->data);
  }
  else {
    return;
  }

  //@todo unnecessary?
  if (!isset($node)) {
    return;
  }

  $tag = variable_get('vud_tag', 'vote');
  $widget = $conf['widget'];

  $block = new stdClass();
  $block->module = 'node';
  $block->delta = $node->nid;
  $block->subject = ($conf['override_title']) ? $conf['override_title_text'] : t('Vote');
  $block->title = t('Vote'); //@todo

  $block->content = theme('vud_widget', $node->nid, $node->type, $tag, $widget);
  $block->content .= theme('vud_points', $node->nid, $node->type, $tag, $widget);

  return $block;
}

/**
 * Implementation of a content_type edit form
 */
function vudpane_node_edit_form(&$form, &$form_state) {
  $conf = $form_state['conf'];

  $form['widget'] = array(
    '#type' => 'select',
    '#title' => t('Widget'),
    '#description' => t('Select the voting widget to use.'),
    '#default_value' => (!empty($conf['widget'])) ? $conf['widget'] : variable_get('vud_node_widget', 'plain'),
    '#options' => vud_widget_get_names(),
  );
}

/**
 * Implementation of a content_type edit form submit callback
 */
function vudpane_node_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];
  }
}
marvil07’s picture

Version: 6.x-2.x-dev » 6.x-3.x-dev
Category: support » feature
Status: Needs review » Active

2.x should not have more features, so changing target

I really never coded for panels, so reviews are welcome :-) (after a initial patch)

mradcliffe’s picture

Thank you for the reply. I'll take a look at things in the 3.x branch.

amitaibu’s picture

@re #7:

In order to add this plugin, one should add in their custom module (replace "foo" with your custom module name):

/**
 * Implementation of hook_ctools_plugin_directory().
 */
function foo_ctools_plugin_directory($module, $plugin) {
  if ($module == 'ctools' && !empty($plugin)) {
    return "plugins/$plugin";
  }
}

@mradcliffe:

 if (!isset($node)) {

This is not needed since the node context is required.

If you can finish the @todo, and roll the patch, then we can proceed. Code so far looks good.

henrijs.seso’s picture

Updated version of #7. Lot of small changes. Like function names dont need to be in $plugin if standard naming is used, $default value fix in settings form, no need to clone $node, added admin title so widget is shown in pane title, TODO would be to use Name in stead of machine name.


<?php
// $Id:$
//

/**
* Plugin definition
*/
$plugin = array(
  'single' => TRUE,
  'title' => t('Node: Vote Up/Down'),
  'icon' => 'icon_vud.png',  //@todo
  'description' => t('The Vote Up/Down widget for a node.'),
  'required context' => new ctools_context_required(t('Node'), 'node'),
  'category' => t('Node'),
  'defaults' => array(
    'override_title' => FALSE,
    'override_title_text' => '',
    'widget' => '',
  ),
);

/**
* Implementation of render callback
*/
function MODULENAME_content_type_render($subtype, $conf, $args, $context) {
  if (!isset($context->data)) {
    return;
  }
  $tag = variable_get('vud_tag', 'vote');
  $widget = $conf['widget'];
  $block = new stdClass();
  $block->module = 'vud';
  $block->delta = $context->data->nid;
  $block->title = t('Vote');
  $block->content = theme('vud_widget', $context->data->nid, $context->data->type, $tag, $widget);
  $block->content .= theme('vud_points', $context->data->nid, $context->data->type, $tag, $widget);
  return $block;
}

/**
* Implementation of a content_type edit form
*/
function MODULENAME_content_type_edit_form(&$form, &$form_state) {
  $conf = $form_state['conf'];
  $form['widget'] = array(
    '#type' => 'radios',
    '#title' => t('Widget'),
    '#description' => t('Select the voting widget to use.'),
    '#default_value' => $conf['widget'],
    '#options' => vud_widget_get_names(),
  );
}

/**
* Implementation of a content_type edit form submit callback
*/
function MODULENAME_content_type_edit_form_submit(&$form, &$form_state) {
  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 MODULENAME_content_type_admin_title($subtype, $conf, $context) {
  return t('VUD widget ') . $conf['widget'];
}

dabeast’s picture

I'm sorry, I am having some trouble implementing #11. When I implement this as a new module, I get a

Fatal error: Class 'ctools_context_required' not found in /sites/all/modules/ctools/ctools_plugin_example/ctools_plugin_example.module on line 109

that refers to

required context' => new ctools_context_required(t('Node'), 'node'),

in the above code. Could somebody tell me what I am doing wrong?

Thanks

henrijs.seso’s picture

#12 ctools_plugin_example? did you create new module for this code?

dabeast’s picture

I did include a vudpane.inc file in the plugins directory of a custom module and it works well. Thanks for your reply and for creating this functionality.

codekarate’s picture

I ran into a similar error encountered in #12 but ended up figuring out how to get it to work. In case anyone else runs into the same problem I wrote up a quick blog post which may be helpful http://codekarate.com/content/build-ctools-plugin-panels

loparr’s picture

Hi,
I followed your blog but I must do something wrong. After enabling the module, it shows
@file * vudwidget.module */ /** * Implementation of hook_ctools_plugin_directory(). */ function vudwidget_ctools_plugin_directory($module, $plugin) { if ($module == 'ctools') { return 'plugins/' . $plugin; } }
in the upper side of my screen.
Moreover, opening new content in panels is not possible.

Maybe I dont understand the directory structure >
Does plugins directory go inside vudwidget directory?

Any advice?

Thank you very much

marvil07’s picture

Title: print voting widget in a panel » Expose widgets to panels
Version: 6.x-3.x-dev » 7.x-1.x-dev
Status: Active » Postponed

No more features for 6.x-3.x now that it is the stable branch, moving to 7.x-1.x as postponed until basic port is ready.

csc4’s picture

Many thanks to OP and smthomas - works a treat!

nikkwong’s picture

Can anyone confirm this module is working at all in drupal 7?

marvil07’s picture

Issue summary: View changes
Status: Postponed » Active