
Update commons modules to release 7.12, and move the codebase under modules/commons instead of constant fetching from remote repository. The commons.make file removed so it is not required to rebuild groups distribution. Change-Id: I3be393ba1af34427e2915b18ab1ad718fd4e54db
172 lines
5.2 KiB
Plaintext
172 lines
5.2 KiB
Plaintext
<?php
|
|
/**
|
|
* @file
|
|
* Code for the Commons polls feature.
|
|
*/
|
|
|
|
include_once 'commons_polls.features.inc';
|
|
|
|
/**
|
|
* Implements hook_commons_entity_integration().
|
|
*/
|
|
function commons_polls_commons_entity_integration() {
|
|
return array(
|
|
'node' => array(
|
|
'poll' => array(
|
|
'media' => TRUE,
|
|
'is_group_content' => TRUE,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Implements hook_commons_bw_group_widget().
|
|
*/
|
|
function commons_polls_commons_bw_group_widget() {
|
|
return array(
|
|
'commons_polls' => array(
|
|
'title' => t('Polls'),
|
|
'type' => 'view',
|
|
'vid' => 'commons_bw_polls',
|
|
'display' => 'default',
|
|
'weight' => 10,
|
|
'bundle' => 'poll',
|
|
),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Implements hook_strongarm_alter().
|
|
*/
|
|
function commons_polls_strongarm_alter(&$items) {
|
|
// Expose the poll content type for 'liking' via the Commons_like module
|
|
// by altering the configuration for the Rate.module widget that it provides.
|
|
if (!empty($items['rate_widgets']->value)) {
|
|
foreach($items['rate_widgets']->value as $key => $widget) {
|
|
if ($widget->name == 'commons_like') {
|
|
if (!in_array('poll', $items['rate_widgets']->value[$key]->node_types)) {
|
|
$items['rate_widgets']->value[$key]->node_types[] = 'poll';
|
|
}
|
|
if (!in_array('poll', $items['rate_widgets']->value[$key]->comment_types)) {
|
|
$items['rate_widgets']->value[$key]->comment_types[] = 'poll';
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// Expose the poll content type for integration with Commons Radioactivity
|
|
// and Commons Groups.
|
|
foreach (array('commons_radioactivity_entity_types', 'commons_groups_entity_types') as $key) {
|
|
if (isset($items[$key])) {
|
|
$items[$key]->value['node']['poll'] = 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Implements hook_views_default_views_alter().
|
|
*
|
|
* Display polls on the browsing widget main view.
|
|
*/
|
|
function commons_polls_views_default_views_alter(&$views) {
|
|
if (!empty($views['commons_bw_all'])) {
|
|
$views['commons_bw_all']->display['default']->display_options['filters']['type']['value']['poll'] = 'poll';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Implements hook_form_FROM_ID_alter().
|
|
*/
|
|
function commons_polls_form_commons_bw_partial_node_form_alter(&$form, &$form_state) {
|
|
if (empty($form['#entity']) || $form['#entity']->type != 'poll') {
|
|
return;
|
|
}
|
|
|
|
$language = $form['body']['#language'];
|
|
$form['body'][$language][0]['#title_display'] = 'invisible';
|
|
$form['body'][$language][0]['#required'] = TRUE;
|
|
$form['body'][$language][0]['#placeholder'] = t('Enter a question, e.g. "What is your favorite color?"');
|
|
$form['body'][$language][0]['#resizable'] = FALSE;
|
|
$form['body']['#weight'] = -10;
|
|
|
|
// Prepare the form for collapsing.
|
|
$form['body']['#attributes']['class'][] = 'trigger-field';
|
|
foreach (array('field_media', 'field_image', 'og_group_ref', 'choice_wrapper', 'actions') as $field) {
|
|
if (isset($form[$field])) {
|
|
$form[$field]['#attributes']['class'][] = 'hideable-field';
|
|
}
|
|
}
|
|
|
|
// Add the poll choices widget.
|
|
$form['choice_wrapper'] = array(
|
|
'#tree' => FALSE,
|
|
'#weight' => -4,
|
|
'#prefix' => '<div class="hideable-field clearfix" id="poll-choice-wrapper">',
|
|
'#suffix' => '</div>',
|
|
);
|
|
|
|
// Container for just the poll choices.
|
|
$form['choice_wrapper']['choice'] = array(
|
|
'#prefix' => '<div id="poll-choices">',
|
|
'#suffix' => '</div>',
|
|
'#theme' => 'poll_choices',
|
|
);
|
|
|
|
for ($delta = 0; $delta < 10; $delta++) {
|
|
$form['choice_wrapper']['choice'][$delta] = _poll_choice_form($delta, NULL, '', 0, $delta);
|
|
|
|
if ($delta >= 2) {
|
|
$form['choice_wrapper']['choice'][$delta]['#attributes'] = array('class' => array('hidden'));
|
|
}
|
|
}
|
|
|
|
$form['choice_wrapper']['add_choice'] = array(
|
|
'#markup' => '<a href="#" id="add-choice">' . t('Add more choices') . '</a>',
|
|
);
|
|
|
|
$form['#attached']['js'] = array(drupal_get_path('module', 'commons_polls') . '/js/commons_polls_partial_form.js');
|
|
|
|
$form['actions']['submit']['#value'] = t('Create');
|
|
|
|
$form['#pre_render'][] = 'commons_polls_form_commons_bw_partial_node_form_after_build';
|
|
|
|
// Submit handler to process the choices.
|
|
array_unshift($form['#submit'], 'commons_polls_form_commons_bw_partial_node_form_submit');
|
|
}
|
|
|
|
/**
|
|
* Submit handler.
|
|
* Set poll settings on the node.
|
|
*/
|
|
function commons_polls_form_commons_bw_partial_node_form_submit(&$form, &$form_state) {
|
|
$node = $form['#entity'];
|
|
$node->choice = $form_state['values']['choice'];
|
|
$node->runtime = 0;
|
|
$node->active = TRUE;
|
|
}
|
|
|
|
/**
|
|
* After-build call-back.
|
|
* See commons_polls_form_commons_bw_partial_node_form_alter().
|
|
*/
|
|
function commons_polls_form_commons_bw_partial_node_form_after_build($form) {
|
|
$language = $form['body']['#language'];
|
|
$form['body'][$language][0]['#pre_render'] = array();
|
|
$form['body'][$language][0]['format']['#access'] = FALSE;
|
|
$form['body'][$language][0]['value']['#rows'] = 3;
|
|
|
|
return $form;
|
|
}
|
|
|
|
/**
|
|
* Implements hook_views_pre_render().
|
|
*/
|
|
function commons_polls_views_pre_render(&$view) {
|
|
// Improve the browsing widget empty text when displayed outside of a group.
|
|
// TODO: Enable og_context and check group context instead of looking for an
|
|
// empty first argument.
|
|
if (empty($view->args[0]) && $view->name == 'commons_bw_polls') {
|
|
$view->display_handler->handlers['empty']['area']->options['content'] = t('No polls have been created.');
|
|
}
|
|
}
|