You are here

token_insert.module in Token Insert 6.2

Same filename and directory in other branches
  1. 7.2 token_insert.module

wysiwyg plugin hook.

File

token_insert.module
View source
<?php

// $Id$

/**
 * @file
 * wysiwyg plugin hook.
 */
function token_insert_perm() {
  return array(
    'administer token insert settings',
    'use token insert',
  );
}
function token_insert_menu() {
  $items['admin/settings/token_insert'] = array(
    'title' => 'Token insert',
    'description' => 'Change the tokens users can insert.',
    'type' => MENU_NORMAL_ITEM,
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'token_insert_settings_form',
    ),
    'access arguments' => array(
      'administer token insert settings',
    ),
  );
  return $items;
}
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);
}

Functions

Namesort descending Description
token_insert_menu
token_insert_perm @file wysiwyg plugin hook.
token_insert_settings_form