You are here

function fivestar_node_type_tag_form in Fivestar 6.2

Adds fivestar enaable and position to the node-type configuration form.

2 string references to 'fivestar_node_type_tag_form'
fivestar_comment_form_alter in ./fivestar_comment.module
Form alter specification for comments.
fivestar_menu in ./fivestar.module
Implementation of hook_menu().

File

includes/fivestar.admin.inc, line 183
Configuration pages for Fivestar module.

Code

function fivestar_node_type_tag_form(&$form_state, $type_name, $tag = 'vote') {
  $form = array();
  $settings = fivestar_get_settings($type_name, $tag);
  $form_state['fivestar_tag'] = $tag;
  $form_state['fivestar_node_type'] = $type_name;
  $form['fivestar'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable Fivestar rating for the "@tag" tag', array(
      '@tag' => $tag,
    )),
    '#default_value' => $settings['fivestar'],
    '#weight' => -5,
    '#return_value' => 1,
  );
  $form['fivestar_stars'] = array(
    '#type' => 'select',
    '#title' => t('Number of stars'),
    '#options' => drupal_map_assoc(range(1, 10)),
    '#default_value' => $settings['stars'],
    '#weight' => -4,
  );
  $form['labels'] = array(
    '#type' => 'fieldset',
    '#title' => t('Star Labels'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#description' => t('These star labels appear as the link title when javascript is enabled as well as the select list options when javascript is disabled.'),
  );
  $form['labels']['fivestar_labels_enable'] = array(
    '#type' => 'checkbox',
    '#title' => t('Display labels on mouse over'),
    '#default_value' => $settings['labels_enable'],
    '#return_value' => 1,
    '#weight' => -5,
    '#description' => t('When enabled, the star labels will dynamically appear underneath the stars as the user hovers over each star to provide a more descriptive qualitative meaning for each star value.'),
  );

  // Create the Mouseover text forms for each of the rating options
  // This form depends on the number of stars, and these extra textfields will be hidden with javascript
  for ($n = 0; $n <= 10; $n++) {
    $form['labels']['fivestar_label_' . $n] = array(
      '#type' => 'textfield',
      '#title' => $n > 0 ? t('Star @star label', array(
        '@star' => $n,
      )) : t('Cancel label'),
      '#default_value' => $settings['labels'][$n],
      '#prefix' => '<div id="fivestar-label-' . $n . '" class="fivestar-label">',
      '#suffix' => '</div>',
      '#size' => 30,
    );
  }
  $form['direct'] = array(
    '#type' => 'fieldset',
    '#title' => t('Direct rating widget'),
    '#collapsible' => FALSE,
    '#description' => t('These settings allow you to display a rating widget to your users while they are viewing content of this type. Rating will immediately register a vote for that piece of content.'),
    '#weight' => 2,
  );
  $form['direct']['fivestar_style'] = array(
    '#type' => 'select',
    '#title' => t('Star display style'),
    '#default_value' => $settings['star_display'],
    '#options' => array(
      'average' => t('Display average vote value'),
      'user' => t('Display user vote value'),
      'smart' => t('User vote if available, average otherwise'),
      'dual' => t('Both user and average vote'),
    ),
  );
  $form['direct']['fivestar_text'] = array(
    '#type' => 'select',
    '#title' => t('Text display style'),
    '#default_value' => $settings['text_display'],
    '#options' => array(
      'none' => t('Display no text beneath stars'),
      'average' => t('Current average in text'),
      'user' => t('User current vote in text'),
      'smart' => t('User vote if available, average otherwise'),
      'dual' => t('Both user and average vote'),
    ),
  );
  $form['direct']['fivestar_title'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show widget title'),
    '#default_value' => $settings['title_display'],
    '#return_value' => 1,
  );
  $form['direct']['fivestar_feedback'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable feedback during vote saving and deletion'),
    '#default_value' => $settings['feedback_enable'],
    '#return_value' => 1,
  );
  $form['direct']['fivestar_unvote'] = array(
    '#type' => 'checkbox',
    '#title' => t('Allow users to undo their votes'),
    '#default_value' => $settings['unvote_enable'],
    '#return_value' => 1,
  );
  $form['direct']['fivestar_position_teaser'] = array(
    '#type' => 'select',
    '#title' => t('Teaser display'),
    '#default_value' => $settings['position_teaser'],
    '#options' => array(
      'above' => t('Clickable widget above teaser'),
      'below' => t('Clickable widget below teaser'),
      'above_static' => t('Static display above teaser'),
      'below_static' => t('Static display below teaser'),
      'link' => t('Teaser link to full node widget'),
      'hidden' => '<' . t('hidden') . '>',
    ),
  );
  $form['direct']['fivestar_position'] = array(
    '#type' => 'select',
    '#title' => t('Full node display'),
    '#default_value' => $settings['position'],
    '#options' => array(
      'above' => t('Clickable widget above node body'),
      'below' => t('Clickable widget below node body'),
      'above_static' => t('Static display above node body'),
      'below_static' => t('Static display below node body'),
      'hidden' => '<' . t('hidden') . '>',
    ),
  );
  $form['direct']['fivestar_direct_preview'] = array(
    '#type' => 'item',
    '#title' => t('Direct rating widget preview'),
    '#value' => theme('fivestar_preview', $form['direct']['fivestar_style']['#default_value'], $form['direct']['fivestar_text']['#default_value'], $form['fivestar_stars']['#default_value'], $form['direct']['fivestar_unvote']['#default_value'], $form['direct']['fivestar_title']['#default_value'] ? NULL : FALSE, $form['labels']['fivestar_labels_enable']['#default_value'], $settings['labels']),
  );
  if (!$form['fivestar']['#default_value']) {
    $form['direct']['fivestar_direct_preview']['#value'] = theme('fivestar_preview_wrapper', '');
  }
  else {
    $form['direct']['fivestar_direct_preview']['#value'] = theme('fivestar_preview_wrapper', $form['direct']['fivestar_direct_preview']['#value']);
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}