You are here

token_insert_ckeditor.module in Token Insert 7.2

Same filename and directory in other branches
  1. 6.2 token_insert_ckeditor/token_insert_ckeditor.module

This module provides CKEditor module support for token insert.

File

token_insert_ckeditor/token_insert_ckeditor.module
View source
<?php

/**
 * @file
 * This module provides CKEditor module support for token insert.
 */

/**
 * Implements hook_menu().
 */
function token_insert_ckeditor_menu() {
  $items = array();
  $items['token_insert_ckeditor/insert/%'] = array(
    'page callback' => '_token_insert_ckeditor_tokens_output',
    'page arguments' => array(
      2,
    ),
    'access arguments' => array(
      'access content',
    ),
    'theme callback' => 'ajax_base_page_theme',
    'type' => MENU_CALLBACK,
    'delivery callback' => 'ajax_deliver',
  );
  return $items;
}

/**
 * Implements hook_ckeditor_plugin().
 */
function token_insert_ckeditor_ckeditor_plugin() {
  return array(
    'token_insert_ckeditor' => array(
      'name' => 'token_insert_ckeditor',
      'desc' => t('Token insert'),
      'path' => drupal_get_path('module', 'token_insert_ckeditor') . '/plugins/token_insert_ckeditor/',
      'buttons' => array(
        'TokenInsert' => array(
          'icon' => 'images/insert.png',
          'label' => 'Token insert',
        ),
      ),
    ),
  );
}

/**
 * Print out the tokens in a CKEditor-readable format.
 */
function _token_insert_ckeditor_tokens_output($id) {
  $html = theme('token_insert_tree');
  $commands = array();
  $commands[] = array(
    'command' => 'insert',
    'method' => 'html',
    'selector' => '#' . $id,
    'data' => $html,
    'settings' => NULL,
  );
  $commands[] = ajax_command_invoke('#' . $id, 'trigger', array(
    'token-insert-table-loaded',
  ));
  return array(
    '#type' => 'ajax',
    '#commands' => $commands,
  );
}

/**
 * Implements hook_element_info_alter().
 */
function token_insert_ckeditor_element_info_alter(&$types) {
  $types['text_format']['#pre_render'][] = 'token_insert_ckeditor_pre_render_text_format';
}
function token_insert_ckeditor_pre_render_text_format($element) {
  $element['#attached']['library'][] = array(
    'system',
    'drupal.ajax',
  );
  return $element;
}
function token_insert_ckeditor_custom_theme() {
  if (strpos(current_path(), 'token_insert_ckeditor/insert') === 0) {
    return 'seven';
  }
}