editor.api.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * @file
  4. * Documentation for Text Editor API.
  5. */
  6. use Drupal\filter\FilterFormatInterface;
  7. /**
  8. * @addtogroup hooks
  9. * @{
  10. */
  11. /**
  12. * Performs alterations on text editor definitions.
  13. *
  14. * @param array $editors
  15. * An array of metadata of text editors, as collected by the plugin annotation
  16. * discovery mechanism.
  17. *
  18. * @see \Drupal\editor\Plugin\EditorBase
  19. */
  20. function hook_editor_info_alter(array &$editors) {
  21. $editors['some_other_editor']['label'] = t('A different name');
  22. $editors['some_other_editor']['library']['module'] = 'myeditoroverride';
  23. }
  24. /**
  25. * Modifies JavaScript settings that are added for text editors.
  26. *
  27. * @param array $settings
  28. * All the settings that will be added to the page for the text formats to
  29. * which a user has access.
  30. */
  31. function hook_editor_js_settings_alter(array &$settings) {
  32. if (isset($settings['editor']['formats']['basic_html'])) {
  33. $settings['editor']['formats']['basic_html']['editor'] = 'MyDifferentEditor';
  34. $settings['editor']['formats']['basic_html']['editorSettings']['buttons'] = ['strong', 'italic', 'underline'];
  35. }
  36. }
  37. /**
  38. * Modifies the text editor XSS filter that will used for the given text format.
  39. *
  40. * Is only called when an EditorXssFilter will effectively be used; this hook
  41. * does not allow one to alter that decision.
  42. *
  43. * @param string &$editor_xss_filter_class
  44. * The text editor XSS filter class that will be used.
  45. * @param \Drupal\filter\FilterFormatInterface $format
  46. * The text format configuration entity. Provides context based upon which
  47. * one may want to adjust the filtering.
  48. * @param \Drupal\filter\FilterFormatInterface|null $original_format
  49. * (optional) The original text format configuration entity (when switching
  50. * text formats/editors). Also provides context based upon which one may want
  51. * to adjust the filtering.
  52. *
  53. * @see \Drupal\editor\EditorXssFilterInterface
  54. */
  55. function hook_editor_xss_filter_alter(&$editor_xss_filter_class, FilterFormatInterface $format, FilterFormatInterface $original_format = NULL) {
  56. $filters = $format->filters()->getAll();
  57. if (isset($filters['filter_wysiwyg']) && $filters['filter_wysiwyg']->status) {
  58. $editor_xss_filter_class = '\Drupal\filter_wysiwyg\EditorXssFilter\WysiwygFilter';
  59. }
  60. }
  61. /**
  62. * @} End of "addtogroup hooks".
  63. */