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