1. 8.3.x core/modules/ckeditor/ckeditor.module
  2. 8.0.x core/modules/ckeditor/ckeditor.module
  3. 8.1.x core/modules/ckeditor/ckeditor.module
  4. 8.2.x core/modules/ckeditor/ckeditor.module
  5. 8.4.x core/modules/ckeditor/ckeditor.module

Provides integration with the CKEditor WYSIWYG editor.

File

core/modules/ckeditor/ckeditor.module
View source
  1. <?php
  2. /**
  3. * @file
  4. * Provides integration with the CKEditor WYSIWYG editor.
  5. */
  6. use Drupal\Component\Utility\UrlHelper;
  7. use Drupal\Core\Routing\RouteMatchInterface;
  8. use Drupal\editor\Entity\Editor;
  9. /**
  10. * Implements hook_help().
  11. */
  12. function ckeditor_help($route_name, RouteMatchInterface $route_match) {
  13. switch ($route_name) {
  14. case 'help.page.ckeditor':
  15. $output = '';
  16. $output .= '<h3>' . t('About') . '</h3>';
  17. $output .= '<p>' . t('The CKEditor module provides a highly-accessible, highly-usable 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 the <a href=":doc_url">online documentation for the CKEditor module</a> and the <a href=":cke_url">CKEditor website</a>.', array( ':doc_url' => 'https://www.drupal.org/documentation/modules/ckeditor', ':cke_url' => 'http://ckeditor.com', ':text_editor' => \Drupal::url('help.page', array('name' => 'editor')))) . '</p>';
  18. $output .= '<h3>' . t('Uses') . '</h3>';
  19. $output .= '<dl>';
  20. $output .= '<dt>' . t('Enabling CKEditor for individual text formats') . '</dt>';
  21. $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' => \Drupal::url('filter.admin_overview'), ':text_editor' => \Drupal::url('help.page', array('name' => 'editor')), ':filter' => \Drupal::url('help.page', array('name' => 'filter')))) . '</dd>';
  22. $output .= '<dt>' . t('Configuring the toolbar') . '</dt>';
  23. $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>';
  24. $output .= '<dt>' . t('Formatting content') . '</dt>';
  25. $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' => \Drupal::url('help.page', array('name' => 'filter')))) . '</dd>';
  26. $output .= '<dt>' . t('Toggling between formatted text and HTML source') . '</dt>';
  27. $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>';
  28. $output .= '<dt>' . t('Check my spelling as I type') . '</dt>';
  29. $output .= '<dd>' . t('By default, CKEditor is configured to leverage your browser\'s spell check capability. Make sure your browser\'s spell checker is enabled in your browser\'s settings. To access suggested corrections for misspelled words, it may be necessary to hold the <em>Control</em> or <em>command</em> (Mac) key while right-clicking the misspelling.') . '</dd>';
  30. $output .= '<dt>' . t('Accessibility features') . '</dt>';
  31. $output .= '<dd>' . t('The built in WYSIWYG editor (CKEditor) comes with a number of <a href=":features">accessibility features</a>. CKEditor comes with built in <a href=":shortcuts">keyboard shortcuts</a>, which can be beneficial for both power users and keyboard only users.', array(':features' => 'http://docs.ckeditor.com/#!/guide/dev_a11y', ':shortcuts' => 'http://docs.ckeditor.com/#!/guide/dev_shortcuts')) . '</dd>';
  32. $output .= '<dt>' . t('Generating accessible content') . '</dt>';
  33. $output .= '<dd>' . t('HTML tables can be created with both table headers as well as caption/summary elements. Alt text is required by default on images added through CKEditor (note that this can be overridden). Semantic HTML5 figure/figcaption are available to add captions to images.') . '</dd>';
  34. $output .= '</dl>';
  35. return $output;
  36. }
  37. }
  38. /**
  39. * Implements hook_theme().
  40. */
  41. function ckeditor_theme() {
  42. return array(
  43. 'ckeditor_settings_toolbar' => array(
  44. 'file' => 'ckeditor.admin.inc',
  45. 'variables' => array('editor' => NULL, 'plugins' => NULL),
  46. ),
  47. );
  48. }
  49. /**
  50. * Implements hook_ckeditor_css_alter().
  51. */
  52. function ckeditor_ckeditor_css_alter(array &$css, Editor $editor) {
  53. if (!$editor->hasAssociatedFilterFormat()) {
  54. return;
  55. }
  56. // Add the filter caption CSS if the text format associated with this text
  57. // editor uses the filter_caption filter. This is used by the included
  58. // CKEditor DrupalImageCaption plugin.
  59. if ($editor->getFilterFormat()->filters('filter_caption')->status) {
  60. $css[] = drupal_get_path('module', 'filter') . '/css/filter.caption.css';
  61. }
  62. }
  63. /**
  64. * Retrieves the default theme's CKEditor stylesheets.
  65. *
  66. * Themes may specify iframe-specific CSS files for use with CKEditor by
  67. * including a "ckeditor_stylesheets" key in their .info.yml file.
  68. *
  69. * @code
  70. * ckeditor_stylesheets:
  71. * - css/ckeditor-iframe.css
  72. * @endcode
  73. */
  74. function _ckeditor_theme_css($theme = NULL) {
  75. $css = array();
  76. if (!isset($theme)) {
  77. $theme = \Drupal::config('system.theme')->get('default');
  78. }
  79. if (isset($theme) && $theme_path = drupal_get_path('theme', $theme)) {
  80. $info = system_get_info('theme', $theme);
  81. if (isset($info['ckeditor_stylesheets'])) {
  82. $css = $info['ckeditor_stylesheets'];
  83. foreach ($css as $key => $url) {
  84. if (UrlHelper::isExternal($url)) {
  85. $css[$key] = $url;
  86. }
  87. else {
  88. $css[$key] = $theme_path . '/' . $url;
  89. }
  90. }
  91. }
  92. if (isset($info['base theme'])) {
  93. $css = array_merge(_ckeditor_theme_css($info['base theme']), $css);
  94. }
  95. }
  96. return $css;
  97. }
  98. /**
  99. * Implements hook_library_info_alter().
  100. */
  101. function ckeditor_library_info_alter(&$libraries, $extension) {
  102. // Pass Drupal's JS cache-busting string via settings along to CKEditor.
  103. // @see http://docs.ckeditor.com/#!/api/CKEDITOR-property-timestamp
  104. if ($extension === 'ckeditor' && isset($libraries['drupal.ckeditor'])) {
  105. $query_string = \Drupal::state()->get('system.css_js_query_string') ?: '0';
  106. $libraries['drupal.ckeditor']['drupalSettings']['ckeditor']['timestamp'] = $query_string;
  107. }
  108. }

Functions

Namesort descending Description
ckeditor_ckeditor_css_alter Implements hook_ckeditor_css_alter().
ckeditor_help Implements hook_help().
ckeditor_library_info_alter Implements hook_library_info_alter().
ckeditor_theme Implements hook_theme().
_ckeditor_theme_css Retrieves the default theme's CKEditor stylesheets.