You are here

function rate_field_settings_form in Rate 7.2

Implements hook_field_settings_form().

File

./rate.module, line 134
Main module file for the Rate module.

Code

function rate_field_settings_form($field, $instance, $has_data) {
  $settings = $field['settings'];
  $form['tag'] = array(
    '#type' => 'textfield',
    '#title' => t('Tag'),
    '#default_value' => $settings['tag'],
    '#description' => t('Tag used for VotingAPI. Widgets with the same tag share their voting results. Use "vote" for global use.'),
    '#required' => TRUE,
  );
  $form['permissions'] = array(
    '#type' => 'fieldset',
    '#title' => t('Permissions'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );

  // Select roles.
  $res = db_select('role', 'r')
    ->fields('r', array(
    'rid',
    'name',
  ))
    ->orderBy('name', 'asc')
    ->execute();
  $options = array();
  foreach ($res as $rec) {
    $options[$rec->rid] = $rec->name;
  }
  $form['permissions']['roles'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Roles'),
    '#options' => $options,
    '#default_value' => $settings['roles'],
    '#description' => t('Allow voting only for the selected role(s). If you select no roles, all users are allowed to vote.'),
  );
  $form['permissions']['allow_voting_by_author'] = array(
    '#type' => 'checkbox',
    '#title' => t('Allow author to rate his / her own content'),
    '#default_value' => $settings['allow_voting_by_author'],
    '#description' => t('Will change the state to disabled. Always true for anonymous users.'),
  );
  $options = array(
    RATE_NOPERM_REDIRECT_WITH_MESSAGE => t('Redirect to login and show message'),
    RATE_NOPERM_REDIRECT_WITHOUT_MESSAGE => t('Redirect to login but do not show a message'),
    RATE_NOPERM_SHOW_DISABLED_WIDGET => t('Show a disabled widget (with non clickable buttons)'),
    RATE_NOPERM_HIDE_WIDGET => t('Hide widget'),
  );
  $form['permissions']['noperm_behavior'] = array(
    '#type' => 'radios',
    '#title' => t('Behavior when user has no permission to vote'),
    '#options' => $options,
    '#default_value' => $settings['noperm_behavior'],
    '#description' => t('Choose an action what will happen if a user clicks on the widget but doesn\'t have the permission to vote.'),
  );
  return $form;
}