View source
<?php
$plugin = array(
'title' => t('Rate widget'),
'description' => t('A rate widget for this node.'),
'category' => t('Node'),
'required context' => new ctools_context_required(t('Node'), 'node'),
'render callback' => 'rate_panels_rate_widget_render',
'edit form' => 'rate_panels_rate_widget_form',
'defaults' => array(
'build_mode' => 'RATE_FULL',
'widget_name' => '',
),
);
function rate_panels_rate_widget_form($form, &$form_state) {
$conf = $form_state['conf'];
$form['build_mode'] = array(
'#title' => t('Build mode'),
'#type' => 'select',
'#options' => array(
RATE_FULL => t('RATE_FULL'),
RATE_COMPACT => t('RATE_COMPACT'),
RATE_DISABLED => t('RATE_DISABLED'),
RATE_CLOSED => t('RATE_CLOSED'),
RATE_COMPACT_DISABLED => t('RATE_COMPACT_DISABLED'),
),
'#default_value' => $conf['build_mode'],
);
$widgets = variable_get(RATE_VAR_WIDGETS, array());
$widget_options = array();
foreach ($widgets as $id => $widget) {
$widget_options[$id] = $widget->title;
}
$form['widget_name'] = array(
'#title' => t('Widget'),
'#type' => 'select',
'#options' => $widget_options,
'#default_value' => $conf['widget_name'],
);
return $form;
}
function rate_panels_rate_widget_form_submit($form, &$form_state) {
foreach (array_keys($form_state['plugin']['defaults']) as $key) {
$form_state['conf'][$key] = $form_state['values'][$key];
}
}
function rate_panels_rate_widget_render($subtype, $conf, $panel_args, $context) {
if (empty($context) || empty($context->data)) {
return;
}
$node = $context->data;
$type = node_type_get_type($node);
$widget_code = array(
'#markup' => rate_generate_widget($conf['widget_name'], 'node', $node->nid, $conf['build_mode']),
);
$block = new stdClass();
$block->module = 'rate_extras';
$block->title = $type->title_label;
$block->content = $widget_code;
$block->delta = $node->nid;
return $block;
}