You are here

function uc_roles_feature_settings in Ubercart 5

Same name and namespace in other branches
  1. 6.2 uc_roles/uc_roles.module \uc_roles_feature_settings()
  2. 7.3 uc_roles/uc_roles.module \uc_roles_feature_settings()

Form builder for role settings

1 string reference to 'uc_roles_feature_settings'
uc_roles_product_feature in uc_roles/uc_roles.module
Implementation of hook_product_feature().

File

uc_roles/uc_roles.module, line 718
Grants roles upon accepted payment of products

Code

function uc_roles_feature_settings() {
  uc_add_js('$(document).ready(function() { if ($("#edit-uc-roles-default-granularity").val() == "never") {$("#edit-uc-roles-default-length").attr("disabled", "disabled").val("");} });', 'inline');
  $default_role_choices = user_roles(TRUE);
  unset($default_role_choices[DRUPAL_AUTHENTICATED_RID]);
  foreach (uc_order_status_list('general') as $status) {
    $statuses[$status['id']] = $status['title'];
  }
  $form['uc_roles_default_order_status'] = array(
    '#type' => 'select',
    '#title' => t('Order status'),
    '#default_value' => variable_get('uc_roles_default_order_status', 'completed'),
    '#description' => t('Where in the order status that the role will be granted. Be aware that if payments are processed automatically, this happens before anonymous customers have an account created. This order status should not be reached before the user account exists.'),
    '#options' => $statuses,
  );
  $form['uc_roles_default_length'] = array(
    '#type' => 'textfield',
    '#title' => t('Default expiration'),
    '#default_value' => variable_get('uc_roles_default_granularity', 'never') == 'never' ? NULL : variable_get('uc_roles_default_length', NULL),
    '#size' => 4,
    '#maxlength' => 4,
    '#prefix' => '<div class="expiration">',
    '#suffix' => '</div>',
  );
  $form['uc_roles_default_granularity'] = array(
    '#type' => 'select',
    '#default_value' => variable_get('uc_roles_default_granularity', 'never'),
    '#options' => array(
      'never' => t('never'),
      'day' => t('day(s)'),
      'week' => t('week(s)'),
      'month' => t('month(s)'),
      'year' => t('year(s)'),
    ),
    '#description' => t('The default amount of time a granted Ubercart role will last until it expires.'),
    '#prefix' => '<div class="expiration">',
    '#suffix' => '</div>',
    '#attributes' => array(
      //Javascript to disable qty on never select
      'onchange' => 'if (this.value == "never") {$("#edit-uc-roles-default-length").attr("disabled", "disabled").val("");} else {$("#edit-uc-roles-default-length").removeAttr("disabled");}',
    ),
  );
  $form['uc_roles_default_role'] = array(
    '#type' => 'select',
    '#title' => t('Default role'),
    '#default_value' => variable_get('uc_roles_default_role', NULL),
    '#description' => t('The default role Ubercart grants on specified products.'),
    '#options' => _get_role_choices(),
  );
  $form['uc_roles_default_role_choices'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Product roles'),
    '#default_value' => variable_get('uc_roles_default_role_choices', array()),
    '#multiple' => TRUE,
    '#description' => t('These are roles that Ubercart can grant to customers who purchase specified products. If there are no choices here, you will need to <a href="!url">create new roles</a>.', array(
      '!url' => url('admin/user/roles', 'destination=admin/store/settings/products/edit/features'),
    )),
    '#options' => $default_role_choices,
  );
  $form['uc_roles_expiration_display'] = array(
    '#type' => 'fieldset',
    '#title' => t('Expiration display'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['uc_roles_expiration_display']['uc_roles_default_show_expiration'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show expirations on user page'),
    '#default_value' => variable_get('uc_roles_default_show_expiration', TRUE),
    '#description' => t('If users have any role expirations they will be displayed on their account page.'),
  );
  $form['uc_roles_expiration_display']['uc_roles_default_expiration_header'] = array(
    '#type' => 'textfield',
    '#title' => t('Header'),
    '#default_value' => variable_get('uc_roles_default_expiration_header', uc_get_message('uc_roles_user_expiration_header')),
  );
  $form['uc_roles_expiration_display']['uc_roles_default_expiration_title'] = array(
    '#type' => 'textfield',
    '#title' => t('Title'),
    '#default_value' => variable_get('uc_roles_default_expiration_title', uc_get_message('uc_roles_user_expiration_title')),
  );
  $form['uc_roles_expiration_display']['uc_roles_default_expiration_message'] = array(
    '#type' => 'textfield',
    '#title' => t('Message'),
    '#default_value' => variable_get('uc_roles_default_expiration_message', uc_get_message('uc_roles_user_expiration_message')),
    '#description' => t('The message, with its accompanying title, and the header displayed above all role expirations. In the <strong>Title</strong> & <strong>Message</strong> fields "!role_name" and "!date" will translate to the corresponding Drupal role name and role expiration date.'),
  );
  return $form;
}