You are here

function token_insert_settings_form in Token Insert 6.2

Same name and namespace in other branches
  1. 7.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 29
wysiwyg plugin hook.

Code

function token_insert_settings_form(&$form_state) {
  $form = array();
  $form['tokens_per_role'] = array(
    '#type' => 'fieldset',
    '#title' => t('Token Insert per user role'),
    '#description' => t('Configure available tokens per user role'),
    '#collapsible' => FALSE,
  );
  $form['tokens_per_role']['token_insert_use_tokens_per_role'] = array(
    '#type' => 'checkbox',
    '#title' => t('Use tokens per user role'),
    '#default_value' => variable_get('token_insert_use_tokens_per_role', 0),
  );
  $roles['global'] = 'global';
  if (variable_get('token_insert_use_tokens_per_role', 0)) {
    $roles += user_roles(TRUE, 'use token insert');
  }
  $all_tokens = token_get_list();
  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,
    );
    foreach ($all_tokens as $category => $tokens) {
      $form[$rid . '_available_tokens'][$category] = array(
        '#type' => 'fieldset',
        '#title' => t($category),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
      );
      $options = array();
      $defaults = array();
      foreach ($tokens as $token => $description) {
        $options[$token] = $category . ' : [' . $token . '] : ' . t($description);
        $defaults[$token] = 0;
      }
      $category_safe = str_replace(' ', '_', $category);
      $form[$rid . '_available_tokens'][$category]['token_insert_' . $rid . '_used_tokens_' . $category_safe] = array(
        '#type' => 'checkboxes',
        '#title' => t('Select tokens'),
        '#default_value' => variable_get('token_insert_' . $rid . '_used_tokens_' . $category_safe, $defaults),
        '#options' => $options,
        '#description' => t('Select ' . $category . ' tokens available for insert.'),
      );
    }
  }
  return system_settings_form($form);
}