You are here

token_insert_wysiwyg.module in Token Insert 7.2

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

This module provides wysiwyg support for token insert.

File

token_insert_wysiwyg/token_insert_wysiwyg.module
View source
<?php

/**
 * @file
 * This module provides wysiwyg support for token insert.
 */
function token_insert_wysiwyg_wysiwyg_include_directory($type) {
  switch ($type) {
    case 'plugins':
      return $type;
  }
}

/**
 * Implements hook_element_info_alter().
 */
function token_insert_wysiwyg_element_info_alter(&$types) {
  $types['text_format']['#pre_render'][] = 'token_insert_wysiwyg_pre_render_text_format';
}
function token_insert_wysiwyg_pre_render_text_format($element) {

  // filter_process_format() copies properties to the expanded 'value' child
  // element. Skip this text format widget, if it contains no 'format' or when
  // the current user does not have access to edit the value.
  if (!isset($element['format']) || !empty($element['value']['#disabled'])) {
    return $element;
  }

  // WYSIWYG module allows modules to programmatically enforce no client-side
  // editor by setting the #wysiwyg property to FALSE.
  if (isset($element['#wysiwyg']) && !$element['#wysiwyg']) {
    return $element;
  }
  $element['#attached']['library'][] = array(
    'system',
    'ui.dialog',
  );
  $element['#attached']['library'][] = array(
    'system',
    'ui.draggable',
  );
  $element['#attached']['library'][] = array(
    'system',
    'drupal.ajax',
  );
  return $element;
}
function token_insert_wysiwyg_menu() {
  $items = array();
  $items['token_insert_wysiwyg/insert/%'] = array(
    'page callback' => 'token_insert_wysiwyg_page',
    'page arguments' => array(
      2,
    ),
    'access callback' => TRUE,
    'delivery callback' => 'ajax_deliver',
    'type' => MENU_CALLBACK,
  );
  return $items;
}
function token_insert_wysiwyg_page($wysiwyg_instance_id) {
  $commands = array();
  $id = '#token-insert-dialog-' . $wysiwyg_instance_id;
  $commands[] = ajax_command_insert($id, theme('token_insert_tree'));
  $commands[] = array(
    'command' => 'tokenInsertTable',
    'selector' => $id,
    'instance_id' => $wysiwyg_instance_id,
  );
  return array(
    '#type' => 'ajax',
    '#commands' => $commands,
  );
}
function token_insert_wysiwyg_custom_theme() {
  if (strpos(current_path(), 'token_insert_wysiwyg/insert') === 0) {
    return 'seven';
  }
}