wysiwyg.api.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. <?php
  2. /**
  3. * @file
  4. * API documentation for Wysiwyg module.
  5. *
  6. * To implement a "Drupal plugin" button, you need to write a Wysiwyg plugin:
  7. * - Implement hook_wysiwyg_include_directory() to register the directory
  8. * containing plugin definitions.
  9. * - In each plugin definition file, implement hook_INCLUDE_plugin().
  10. * - For each plugin button, implement a JavaScript integration and an icon for
  11. * the button.
  12. *
  13. * @todo Icon: Recommended size and type of image.
  14. *
  15. * For example implementations you may want to look at
  16. * - Image Assist (img_assist)
  17. * - Teaser break plugin (plugins/break; part of WYSIWYG)
  18. * - IMCE (imce_wysiwyg)
  19. */
  20. /**
  21. * Return an array of native editor plugins.
  22. *
  23. * Only to be used for native (internal) editor plugins.
  24. *
  25. * @see hook_wysiwyg_include_directory()
  26. *
  27. * @param $editor
  28. * The internal name of the currently processed editor.
  29. * @param $version
  30. * The version of the currently processed editor.
  31. *
  32. * @return
  33. * An associative array having internal plugin names as keys and an array of
  34. * plugin meta-information as values.
  35. */
  36. function hook_wysiwyg_plugin($editor, $version) {
  37. switch ($editor) {
  38. case 'tinymce':
  39. if ($version > 3) {
  40. return array(
  41. 'myplugin' => array(
  42. // A URL to the plugin's homepage.
  43. 'url' => 'http://drupal.org/project/img_assist',
  44. // The full path to the native editor plugin, no trailing slash.
  45. // Ignored when 'internal' is set to TRUE below.
  46. 'path' => drupal_get_path('module', 'img_assist') . '/drupalimage',
  47. // The name of the plugin's main JavaScript file.
  48. // Ignored when 'internal' is set to TRUE below.
  49. // Default value depends on which editor the plugin is for.
  50. 'filename' => 'editor_plugin.js',
  51. // A list of buttons provided by this native plugin. The key has to
  52. // match the corresponding JavaScript implementation. The value is
  53. // is displayed on the editor configuration form only.
  54. // CKEditor-specific note: The internal button name/key is
  55. // capitalized, i.e. Img_assist.
  56. 'buttons' => array(
  57. 'img_assist' => t('Image Assist'),
  58. ),
  59. // A list of editor extensions provided by this native plugin.
  60. // Extensions are not displayed as buttons and touch the editor's
  61. // internals, so you should know what you are doing.
  62. 'extensions' => array(
  63. 'imce' => t('IMCE'),
  64. ),
  65. // A list of global, native editor configuration settings to
  66. // override. To be used rarely and only when required.
  67. 'options' => array(
  68. 'file_browser_callback' => 'imceImageBrowser',
  69. 'inline_styles' => TRUE,
  70. ),
  71. // Boolean whether the editor needs to load this plugin. When TRUE,
  72. // the editor will automatically load the plugin based on the 'path'
  73. // variable provided. If FALSE, the plugin either does not need to
  74. // be loaded or is already loaded by something else on the page.
  75. // Most plugins should define TRUE here.
  76. 'load' => TRUE,
  77. // Boolean whether this plugin is a native plugin, i.e. shipped with
  78. // the editor. Definition must be omitted for plugins provided by
  79. // other modules. TRUE means 'path' and 'filename' above are ignored
  80. // and the plugin is instead loaded from the editor's plugin folder.
  81. 'internal' => TRUE,
  82. // TinyMCE-specific: Additional HTML elements to allow in the markup.
  83. 'extended_valid_elements' => array(
  84. 'img[class|src|border=0|alt|title|width|height|align|name|style]',
  85. ),
  86. ),
  87. );
  88. }
  89. break;
  90. }
  91. }
  92. /**
  93. * Register a directory containing Wysiwyg plugins.
  94. *
  95. * @param $type
  96. * The type of objects being collected: either 'plugins' or 'editors'.
  97. * @return
  98. * A sub-directory of the implementing module that contains the corresponding
  99. * plugin files. This directory must only contain integration files for
  100. * Wysiwyg module.
  101. */
  102. function hook_wysiwyg_include_directory($type) {
  103. switch ($type) {
  104. case 'plugins':
  105. // You can just return $type, if you place your Wysiwyg plugins into a
  106. // sub-directory named 'plugins'.
  107. return $type;
  108. }
  109. }
  110. /**
  111. * Define a Wysiwyg plugin.
  112. *
  113. * Supposed to be used for "Drupal plugins" (cross-editor plugins) only.
  114. *
  115. * @see hook_wysiwyg_plugin()
  116. *
  117. * Each plugin file in the specified plugin directory of a module needs to
  118. * define meta information about the particular plugin provided.
  119. * The plugin's hook implementation function name is built out of the following:
  120. * - 'hook': The name of the module providing the plugin.
  121. * - 'INCLUDE': The basename of the file containing the plugin definition.
  122. * - 'plugin': Static.
  123. *
  124. * For example, if your module's name is 'mymodule' and
  125. * mymodule_wysiwyg_include_directory() returned 'plugins' as plugin directory,
  126. * and this directory contains an "awesome" plugin file named 'awesome.inc', i.e.
  127. * sites/all/modules/mymodule/plugins/awesome.inc
  128. * then the corresponding plugin hook function name is:
  129. * mymodule_awesome_plugin()
  130. *
  131. * @see hook_wysiwyg_include_directory()
  132. *
  133. * @return
  134. * Meta information about the buttons provided by this plugin.
  135. */
  136. function hook_INCLUDE_plugin() {
  137. $plugins['awesome'] = array(
  138. // The plugin's title; defaulting to its internal name ('awesome').
  139. 'title' => t('Awesome plugin'),
  140. // The (vendor) homepage of this plugin; defaults to ''.
  141. 'vendor url' => 'http://drupal.org/project/wysiwyg',
  142. // The path to the button's icon; defaults to
  143. // '/[path-to-module]/[plugins-directory]/[plugin-name]/images'.
  144. 'icon path' => 'path to icon',
  145. // The button image filename; defaults to '[plugin-name].png'.
  146. 'icon file' => 'name of the icon file with extension',
  147. // The button title to display on hover.
  148. 'icon title' => t('Do something'),
  149. // An alternative path to the integration JavaScript; defaults to
  150. // '[path-to-module]/[plugins-directory]/[plugin-name]'.
  151. 'js path' => drupal_get_path('module', 'mymodule') . '/awesomeness',
  152. // An alternative filename of the integration JavaScript; defaults to
  153. // '[plugin-name].js'.
  154. 'js file' => 'awesome.js',
  155. // An alternative path to the integration stylesheet; defaults to
  156. // '[path-to-module]/[plugins-directory]/[plugin-name]'.
  157. 'css path' => drupal_get_path('module', 'mymodule') . '/awesomeness',
  158. // An alternative filename of the integration stylesheet; defaults to
  159. // '[plugin-name].css'.
  160. 'css file' => 'awesome.css',
  161. // An array of settings for this button. Required, but API is still in flux.
  162. 'settings' => array(
  163. ),
  164. // TinyMCE-specific: Additional HTML elements to allow in the markup.
  165. 'extended_valid_elements' => array(
  166. 'tag1[attribute1|attribute2]',
  167. 'tag2[attribute3|attribute4]',
  168. ),
  169. );
  170. return $plugins;
  171. }
  172. /**
  173. * Define a Wysiwyg editor library.
  174. *
  175. * @todo Complete this documentation.
  176. */
  177. function hook_INCLUDE_editor() {
  178. $editor['ckeditor'] = array(
  179. // The official, human-readable label of the editor library.
  180. 'title' => 'CKEditor',
  181. // The URL to the library's homepage.
  182. 'vendor url' => 'http://ckeditor.com',
  183. // The URL to the library's download page.
  184. 'download url' => 'http://ckeditor.com/download',
  185. // A definition of available variants for the editor library.
  186. // The first defined is used by default.
  187. 'libraries' => array(
  188. '' => array(
  189. 'title' => 'Default',
  190. 'files' => array(
  191. 'ckeditor.js' => array('preprocess' => FALSE),
  192. ),
  193. ),
  194. 'src' => array(
  195. 'title' => 'Source',
  196. 'files' => array(
  197. 'ckeditor_source.js' => array('preprocess' => FALSE),
  198. ),
  199. ),
  200. ),
  201. // (optional) A callback to invoke to return additional notes for installing
  202. // the editor library in the administrative list/overview.
  203. 'install note callback' => 'wysiwyg_ckeditor_install_note',
  204. // The minimum and maximum versions the implemetation has been tested with.
  205. // Users will be notified if installing a version not within this range.
  206. 'verified version range' => array('1.2.3', '3.4.5'),
  207. // (optional) A callback to perform migrations of the settings stored in a
  208. // profile when a library change has been detected. Takes a reference to a
  209. // settings object, the processed editor definition, the profile version and
  210. // the installed library version. Migrations should be performed in the
  211. // order changes were introduced by library versions, and the last version
  212. // migrated to should be returned, or FALSE if no migration was possible.
  213. // The returned version should be less than or equal to the highest version
  214. // ( and >= the lowest version) defined in 'verified version range' and
  215. // be as close as possible to, without passing, the installed version.
  216. 'migrate settings callback' => 'wysiwyg_ckeditor_migrate_settings',
  217. // A callback to determine the library's version.
  218. 'version callback' => 'wysiwyg_ckeditor_version',
  219. // A callback to return available themes/skins for the editor library.
  220. 'themes callback' => 'wysiwyg_ckeditor_themes',
  221. // (optional) A callback to perform editor-specific adjustments or
  222. // enhancements for the administrative editor profile settings form.
  223. 'settings form callback' => 'wysiwyg_ckeditor_settings_form',
  224. // (optional) A callback to return an initialization JavaScript snippet for
  225. // this editor library, loaded before the actual library files. The returned
  226. // JavaScript is executed as inline script in a primitive environment,
  227. // before the DOM is loaded; typically used to prime a base path and other
  228. // global window variables for the editor library before it is loaded.
  229. // All implementations should verbosely document what they are doing and
  230. // why that is required.
  231. 'init callback' => 'wysiwyg_ckeditor_init',
  232. // A callback to convert administrative profile/editor settings into
  233. // JavaScript settings.
  234. 'settings callback' => 'wysiwyg_ckeditor_settings',
  235. // A callback to supply definitions of available editor plugins.
  236. 'plugin callback' => 'wysiwyg_ckeditor_plugins',
  237. // A callback to supply global metadata for a single native external plugin.
  238. 'plugin meta callback' => 'wysiwyg_ckeditor_plugin_meta',
  239. // A callback to convert administrative plugin settings for an editor
  240. // profile into JavaScript settings per profile.
  241. 'plugin settings callback' => 'wysiwyg_ckeditor_plugin_settings',
  242. // (optional) Defines the proxy plugin that handles plugins provided by
  243. // Drupal modules, which work in all editors that support proxy plugins.
  244. 'proxy plugin' => array(
  245. 'drupal' => array(
  246. 'load' => TRUE,
  247. 'proxy' => TRUE,
  248. ),
  249. ),
  250. // (optional) A callback to convert proxy plugin settings into JavaScript
  251. // settings.
  252. 'proxy plugin settings callback' => 'wysiwyg_ckeditor_proxy_plugin_settings',
  253. // Defines the list of supported (minimum) versions of the editor library,
  254. // and the respective Drupal integration files to load.
  255. 'versions' => array(
  256. '3.0.0.3665' => array(
  257. 'js files' => array('ckeditor-3.0.js'),
  258. ),
  259. ),
  260. );
  261. return $editor;
  262. }
  263. /**
  264. * Alter editor definitions defined by other modules.
  265. *
  266. * @param array $editors
  267. * The Editors to alter.
  268. */
  269. function hook_wysiwyg_editor_alter(&$editors) {
  270. $editors['editor']['version callback'] = 'my_own_version_callback';
  271. }
  272. /**
  273. * Act on editor profile settings.
  274. *
  275. * This hook is invoked from wysiwyg_get_editor_config() after the JavaScript
  276. * settings have been generated for an editor profile and before the settings
  277. * are added to the page. The settings may be customized or enhanced; typically
  278. * with options that cannot be controlled through Wysiwyg module's
  279. * administrative UI currently.
  280. *
  281. * Modules implementing this hook to enforce settings that can also be
  282. * controlled through the UI should also implement
  283. * hook_form_wysiwyg_profile_form_alter() to adjust or at least indicate on the
  284. * editor profile configuration form that certain/affected settings cannot be
  285. * changed.
  286. *
  287. * @param $settings
  288. * An associative array of JavaScript settings to pass to the editor.
  289. * @param $context
  290. * An associative array containing additional context information:
  291. * - editor: The plugin definition array of the editor.
  292. * - profile: The editor profile object, as loaded from the database.
  293. * - theme: The name of the editor theme/skin.
  294. */
  295. function hook_wysiwyg_editor_settings_alter(&$settings, $context) {
  296. // Each editor has its own collection of native settings that may be extended
  297. // or overridden. Please consult the respective official vendor documentation
  298. // for details.
  299. if ($context['profile']->editor == 'tinymce') {
  300. // Supported values to JSON data types.
  301. $settings['cleanup_on_startup'] = TRUE;
  302. // Function references (callbacks) need special care.
  303. // @see wysiwyg_wrap_js_callback()
  304. $settings['file_browser_callback'] = wysiwyg_wrap_js_callback('myFileBrowserCallback');
  305. // Regular Expressions need special care.
  306. // @see wysiwyg_wrap_js_regexp()
  307. $settings['stylesheetParser_skipSelectors'] = wysiwyg_wrap_js_regexp('(^body\.|^caption\.|\.high|^\.)', 'i');
  308. }
  309. }
  310. /**
  311. * Act on stylesheets used in WYSIWYG mode.
  312. *
  313. * This hook acts like a pre-render callback to the style element normally
  314. * output in the document header. It is invoked before Core has
  315. * sorted/grouped/aggregated stylehsheets and changes made here will only have
  316. * an effect on the stylesheets used in an editor's WYSIWYG mode.
  317. * Wysiwyg will only keep items if their type is 'file' or 'inline' and only if
  318. * they are in the group CSS_THEME.
  319. *
  320. * This hook may be invoked several times in a row with slightly different or
  321. * altered stylesheets if something like Color module is used by a theme.
  322. * Wysiwyg will cache the final list of stylesheets so this hook will only be
  323. * called while the cache is being rebuilt.
  324. *
  325. * Messages set in this hook will not be displayed because the processing is
  326. * done in an internal HTTP request and the page output is ignored.
  327. *
  328. * @param $elements
  329. * The style element which will be rendered. Added stylesheets are found in
  330. * $element['#items']['path/to/stylesheet.css'].
  331. * @param $context
  332. * An array with the following keys:
  333. * - theme: The name of the theme which was used when the list of stylesheets
  334. * was generated.
  335. */
  336. function hook_wysiwyg_editor_styles_alter(&$element, $context) {
  337. if ($context['theme'] == 'alpha') {
  338. unset($element['#items']['sites/all/themes/omega/alpha/css/alpha-debug.css']);
  339. }
  340. }