You are here

function token_insert_settings_form in Token Insert 7.2

Same name and namespace in other branches
  1. 6.2 token_insert.module \token_insert_settings_form()
1 string reference to 'token_insert_settings_form'
token_insert_menu in ./token_insert.module

File

./token_insert.module, line 44
wysiwyg plugin hook.

Code

function token_insert_settings_form($form_state) {
  $form = array();
  $form['general'] = array(
    '#type' => 'fieldset',
    '#title' => t('General settings'),
    '#description' => t('Configure general token insert settings'),
    '#collapsible' => FALSE,
  );
  $form['general']['token_insert_use_tokens_per_role'] = array(
    '#type' => 'checkbox',
    '#title' => t('Use tokens per role'),
    '#default_value' => variable_get('token_insert_use_tokens_per_role', 0),
  );
  $form['general']['token_insert_max_depth'] = array(
    '#type' => 'textfield',
    '#title' => t('Maximum depth'),
    '#default_value' => variable_get('token_insert_max_depth', 1),
    '#description' => t('An integer with the maximum number of token levels to recurse'),
    '#element_validate' => array(
      'element_validate_integer_positive',
    ),
  );
  $roles['global'] = 'global';
  if (variable_get('token_insert_use_tokens_per_role', 0)) {
    $roles += user_roles(TRUE, 'use token insert');
  }
  $all_tokens = token_get_info();
  foreach ($roles as $rid => $role) {
    $title = t("Available tokens for @role", array(
      '@role' => $role,
    ));
    $description = t("Available tokens for users with the '@role' role", array(
      '@role' => $role,
    ));
    if ($rid == 'global') {
      $title = t('Globally available tokens');
      $description = t('Tokens available for every user');
    }
    $form[$rid . '_available_tokens'] = array(
      '#type' => 'fieldset',
      '#title' => $title,
      '#description' => $description,
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    $form[$rid . '_available_tokens'][$rid . '_tokens'] = array(
      '#type' => 'vertical_tabs',
    );
    foreach ($all_tokens['tokens'] as $category => $tokens) {
      $form[$rid . '_available_tokens']['tokens'][$category] = array(
        '#type' => 'fieldset',
        '#title' => t($all_tokens['types'][$category]['name']),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
        '#group' => $rid . '_tokens',
        '#description' => t('Select ' . $all_tokens['types'][$category]['name'] . ' tokens available for insertion.'),
      );
      $options = array();
      $defaults = array();
      foreach ($tokens as $token => $description) {
        $full_token = '[' . $category . ':' . $token . ']';
        $options[$full_token] = $category . ' : [' . $token . '] : ' . t($description['description']);
        $defaults[$full_token] = 0;
      }
      $form[$rid . '_available_tokens']['tokens'][$category]['token_insert_' . $rid . '_all_tokens_' . $category] = array(
        '#type' => 'checkbox',
        '#title' => t('All tokens'),
        '#default_value' => variable_get('token_insert_' . $rid . '_all_tokens_' . $category, FALSE),
        '#description' => t('Make all ' . $all_tokens['types'][$category]['name'] . ' tokens available for insertion.'),
      );
      $form[$rid . '_available_tokens']['tokens'][$category]['token_insert_' . $rid . '_used_tokens_' . $category] = array(
        '#type' => 'checkboxes',
        '#title' => t('Select tokens'),
        '#default_value' => variable_get('token_insert_' . $rid . '_used_tokens_' . $category, array()),
        '#options' => $options,
        '#states' => array(
          'visible' => array(
            // action to take.
            ':input[name=token_insert_' . $rid . '_all_tokens_' . $category . ']' => array(
              'checked' => FALSE,
            ),
          ),
        ),
      );
    }
  }
  $form = system_settings_form($form);
  $form['#submit'][] = 'token_insert_settings_form_submit';
  return $form;
}