ckeditor.module 8.09 KB
Newer Older
1 2 3 4 5 6 7
<?php

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

8 9
use Drupal\editor\Entity\Editor;

10
/**
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
 * Implements hook_help().
 */
function ckeditor_help($path, $arg) {
  switch ($path) {
    case 'admin/help#ckeditor':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('The CKEditor module provides a visual text editor and adds a toolbar to text fields. Users can use buttons to format content and to create semantically correct and valid HTML. The CKEditor module uses the framework provided by the <a href="@text_editor">Text Editor module</a>. It requires JavaScript to be enabled in the browser. For more information, see <a href="@doc_url">the online documentation for the CKEditor module</a> and the <a href="@cke_url">CKEditor website</a>.', array( '@doc_url' => 'https://drupal.org/documentation/modules/ckeditor', '@cke_url'=>'http://ckeditor.com', '@text_editor' => url('admin/help/editor'))) . '</p>';
      $output .= '<h3>' . t('Uses') . '</h3>';
      $output .= '<dl>';
      $output .= '<dt>' . t('Enabling CKEditor for individual text formats') . '</dt>';
      $output .= '<dd>' . t('CKEditor has to be enabled and configured separately for individual text formats from the <a href="@formats">Text formats and editors page</a> because the filter settings for each text format can be different. For more information, see the <a href="@text_editor">Text Editor help page</a> and <a href="@filter">Filter help page</a>.', array('@formats' => url('admin/config/content/formats'), '@text_editor' => url('admin/help/editor'), '@filter' => url('admin/help/filter'))) . '</dd>';
      $output .= '<dt>' . t('Configuring the toolbar') . '</dt>';
      $output .= '<dd>' . t('When CKEditor is chosen from the <em>Text editor</em> drop-down menu, its toolbar configuration is displayed. You can add and remove buttons from the <em>Active toolbar</em> by dragging and dropping them, and additional rows can be added to organize the buttons.') . '</dd>';
      $output .= '<dt>' . t('Formatting content') . '</dt>';
      $output .= '<dd>' . t('CKEditor only allow users to format content in accordance with the filter configuration of the specific text format. If a text format excludes certain HTML tags, the corresponding toolbar buttons are not displayed to users when they edit a text field in this format. For more information see the <a href="@filter">Filter help page</a>.', array('@filter' => url('admin/help/filter'))) . '</dd>';
      $output .= '<dt>' . t('Toggling between formatted text and HTML source') . '</dt>';
      $output .= '<dd>' . t('If the <em>Source</em> button is available in the toolbar, users can click this button to disable the visual editor and edit the HTML source directly. After toggling back, the visual editor uses the allowed HTML tags to format the text — independent of whether buttons for these tags are available in the toolbar. If the text format is set to <em>limit the use of HTML tags</em>, then all excluded tags will be stripped out of the HTML source when the user toggles back to the text editor.') . '</dd>';
      $output .= '</dl>';
      return $output;
  }
}

34
/**
35 36 37 38 39 40 41 42 43 44 45 46
 * 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.',
47
    'version' => \Drupal::VERSION,
48 49 50 51
    'js' => array(
      $module_path . '/js/ckeditor.js' => array(),
      array('data' => $settings, 'type' => 'setting'),
    ),
52 53 54
    'css' => array(
      $module_path . '/css/ckeditor.css' => array(),
    ),
55 56 57 58 59 60 61 62
    '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.',
63
    'version' => \Drupal::VERSION,
64 65 66 67 68
    'js' => array(
      $module_path . '/js/ckeditor.admin.js' => array(),
    ),
    'css' => array(
      $module_path . '/css/ckeditor.admin.css' => array(),
69
      'core/assets/vendor/ckeditor/skins/moono/editor.css' => array(),
70 71 72 73 74 75 76 77
    ),
    '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'),
78
      array('system', 'jquery.ui.touch-punch'),
79 80 81
      array('ckeditor', 'ckeditor'),
      array('editor', 'drupal.editor.admin'),
      array('system', 'underscore')
82 83
    ),
  );
84 85
  $libraries['drupal.ckeditor.drupalimage.admin'] = array(
    'title' => 'Only show the "drupalimage" plugin settings when its button is enabled.',
86
    'version' => \Drupal::VERSION,
87 88 89 90 91 92 93 94 95 96 97
    'js' => array(
      $module_path . '/js/ckeditor.drupalimage.admin.js' => array(),
    ),
    'dependencies' => array(
      array('system', 'jquery'),
      array('system', 'drupal'),
      array('system', 'jquery.once'),
      array('system', 'drupal.vertical-tabs'),
      array('system', 'drupalSettings'),
    ),
  );
98 99
  $libraries['drupal.ckeditor.stylescombo.admin'] = array(
    'title' => 'Only show the "stylescombo" plugin settings when its button is enabled.',
100
    'version' => \Drupal::VERSION,
101 102 103 104 105 106 107 108
    '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'),
109
      array('system', 'drupalSettings'),
110 111
    ),
  );
112 113
  $libraries['drupal.ckeditor.drupalimagecaption-theme'] = array(
    'title' => 'Theming support for the imagecaption plugin.',
114
    'version' => \Drupal::VERSION,
115 116 117 118 119 120 121
    'js' => array(
      $module_path . '/js/plugins/drupalimagecaption/theme.js' => array(),
    ),
    'dependencies' => array(
      array('ckeditor', 'ckeditor'),
    ),
  );
122 123
  $libraries['ckeditor'] = array(
    'title' => 'Loads the main CKEditor library.',
124
    'version' => '4.3-dev — d8-imagecaption branch commit 887d81ac1824008b690e439a1b29eb4f13b51212',
125
    'js' => array(
126
      'core/assets/vendor/ckeditor/ckeditor.js' => array(
127 128
        'preprocess' => FALSE,
      ),
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
    ),
  );

  return $libraries;
}

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

147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
/**
 * Implements hook_ckeditor_css_alter().
 */
function ckeditor_ckeditor_css_alter(array &$css, Editor $editor) {
    $filters = array();
    if (!empty($editor->format)) {
      $filters = entity_load('filter_format', $editor->format)
        ->filters()
        ->getAll();
    }

  // Add the filter caption CSS if the text format associated with this text
  // editor uses the filter_caption filter. This is used by the included
  // CKEditor DrupalImageCaption plugin.
  if (isset($filters['filter_caption']) && $filters['filter_caption']->status) {
    $css[] = drupal_get_path('module', 'filter') . '/css/filter.caption.css';
  }
}

166 167 168 169 170 171 172 173 174 175 176 177 178
/**
 * 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)) {
179
    $theme = \Drupal::config('system.theme')->get('default');
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
  }
  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;
}