ckeditor.module 3.59 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
<?php

/**
 * @file
 * Provides integration with the CKEditor WYSIWYG editor.
 */

/**
 * Implements hook_library_info().
 */
function ckeditor_library_info() {
  $module_path = drupal_get_path('module', 'ckeditor');

  $settings = array(
    'ckeditor' => array(
      'modulePath' => drupal_get_path('module', 'ckeditor'),
    ),
  );
  $libraries['drupal.ckeditor'] = array(
    'title' => 'Drupal behavior to enable CKEditor on textareas.',
    'version' => VERSION,
    'js' => array(
      $module_path . '/js/ckeditor.js' => array(),
      array('data' => $settings, 'type' => 'setting'),
    ),
26 27 28
    'css' => array(
      $module_path . '/css/ckeditor.css' => array(),
    ),
29 30 31 32 33 34 35 36 37 38 39 40 41 42
    'dependencies' => array(
      array('system', 'drupal'),
      array('ckeditor', 'ckeditor'),
      array('editor', 'drupal.editor'),
    ),
  );
  $libraries['drupal.ckeditor.admin'] = array(
    'title' => 'Drupal behavior for drag-and-drop CKEditor toolbar builder UI.',
    'version' => VERSION,
    'js' => array(
      $module_path . '/js/ckeditor.admin.js' => array(),
    ),
    'css' => array(
      $module_path . '/css/ckeditor.admin.css' => array(),
43
      'core/assets/vendor/ckeditor/skins/moono/editor.css' => array(),
44 45 46 47 48 49 50 51
    ),
    'dependencies' => array(
      array('system', 'jquery'),
      array('system', 'drupal'),
      array('system', 'drupalSettings'),
      array('system', 'jquery.once'),
      array('system', 'jquery.ui.sortable'),
      array('system', 'jquery.ui.draggable'),
52
      array('system', 'jquery.ui.touch-punch'),
53 54 55
      array('ckeditor', 'ckeditor'),
      array('editor', 'drupal.editor.admin'),
      array('system', 'underscore')
56 57 58 59 60 61 62 63 64 65 66 67 68
    ),
  );
  $libraries['drupal.ckeditor.stylescombo.admin'] = array(
    'title' => 'Only show the "stylescombo" plugin settings when its button is enabled.',
    'version' => VERSION,
    'js' => array(
      $module_path . '/js/ckeditor.stylescombo.admin.js' => array(),
    ),
    'dependencies' => array(
      array('system', 'jquery'),
      array('system', 'drupal'),
      array('system', 'jquery.once'),
      array('system', 'drupal.vertical-tabs'),
69 70 71
      array('system', 'drupalSettings'),
      // @todo D8 formUpdated event should be debounced already.
      array('system', 'drupal.debounce'),
72 73 74 75
    ),
  );
  $libraries['ckeditor'] = array(
    'title' => 'Loads the main CKEditor library.',
76
    'version' => '4.1',
77
    'js' => array(
78
      'core/assets/vendor/ckeditor/ckeditor.js' => array(
79 80
        'preprocess' => FALSE,
      ),
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
    ),
  );

  return $libraries;
}

/**
 * Implements hook_theme().
 */
function ckeditor_theme() {
  return array(
    'ckeditor_settings_toolbar' => array(
      'file' => 'ckeditor.admin.inc',
      'variables' => array('editor' => NULL, 'plugins' => NULL),
    ),
  );
}

/**
 * Retrieves the default theme's CKEditor stylesheets defined in the .info file.
 *
 * Themes may specify iframe-specific CSS files for use with CKEditor by
 * including a "ckeditor_stylesheets" key in the theme .info file.
 *
 * @code
 * ckeditor_stylesheets[] = css/ckeditor-iframe.css
 * @endcode
 */
function _ckeditor_theme_css($theme = NULL) {
  $css = array();
  if (!isset($theme)) {
112
    $theme = config('system.theme')->get('default');
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
  }
  if ($theme_path = drupal_get_path('theme', $theme)) {
    $info = system_get_info('theme', $theme);
    if (isset($info['ckeditor_stylesheets'])) {
      $css = $info['ckeditor_stylesheets'];
      foreach ($css as $key => $path) {
        $css[$key] = $theme_path . '/' . $path;
      }
    }
    if (isset($info['base theme'])) {
      $css = array_merge(_ckeditor_theme_css($info['base theme'], $css));
    }
  }
  return $css;
}