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