-
Notifications
You must be signed in to change notification settings - Fork 6
/
varbase_editor.module
86 lines (75 loc) · 3.53 KB
/
varbase_editor.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/**
* @file
* Contains varbase_editor.module.
*/
use Drupal\varbase_editor\Plugin\Filter\VarbaseFilterResizeMedia;
/**
* Implements hook_editor_js_settings_alter().
*/
function varbase_editor_editor_js_settings_alter(array &$settings) {
// Remove h1 from Editor formats in the Full HTML (Rich editor) Text format.
if (isset($settings['editor'])
&& isset($settings['editor']['formats'])
&& isset($settings['editor']['formats']['full_html'])
&& isset($settings['editor']['formats']['full_html']['editorSettings'])
&& isset($settings['editor']['formats']['full_html']['editorSettings']['format_tags'])
&& strpos($settings['editor']['formats']['full_html']['editorSettings']['format_tags'], 'h1;')) {
$format_tags = str_replace('h1;', '', $settings['editor']['formats']['full_html']['editorSettings']['format_tags']);
$settings['editor']['formats']['full_html']['editorSettings']['format_tags'] = $format_tags;
}
// Check if the CKEditor Media Resize module is enabled.
if (\Drupal::moduleHandler()->moduleExists('ckeditor_media_resize')) {
if (isset($settings['editor']['formats']['full_html']['editorSettings']['config']['drupalMedia'])) {
// Change the 'resizeUnit' from 'px' to '%'.
$settings['editor']['formats']['full_html']['editorSettings']['config']['drupalMedia']['resizeUnit'] = '%';
// Check if the settings for the 'full_html' format are available.
if (isset($settings['editor']['formats']['full_html']['editorSettings']['config']['drupalMedia']['resizeOptions'])) {
// Add additional resize options to the 'resizeOptions' array.
$settings['editor']['formats']['full_html']['editorSettings']['config']['drupalMedia']['resizeOptions'][] = [
'name' => 'resizeMediaImage:100',
'value' => 100,
'label' => t('Large'),
];
$settings['editor']['formats']['full_html']['editorSettings']['config']['drupalMedia']['resizeOptions'][] = [
'name' => 'resizeMediaImage:50',
'value' => 50,
'label' => t('Medium'),
];
$settings['editor']['formats']['full_html']['editorSettings']['config']['drupalMedia']['resizeOptions'][] = [
'name' => 'resizeMediaImage:25',
'value' => 25,
'label' => t('Small'),
];
}
}
}
}
/**
* Implements hook_library_info_alter().
*/
function varbase_editor_library_info_alter(array &$libraries, $module) {
// Varbase Editor custom style fixes for CKEditor5.
if ($module === 'ckeditor5' && isset($libraries['internal.drupal.ckeditor5.stylesheets'])) {
$libraries['internal.drupal.ckeditor5.stylesheets']['dependencies'][] = 'varbase_editor/ckeditor5';
}
// Add 'varbase_editor/ckeditor5-media-resize' as a dependency
// for ckeditor_media_resize library.
if ($module === 'ckeditor_media_resize' && isset($libraries['editor'])) {
$libraries['editor']['dependencies'][] = 'varbase_editor/ckeditor5-media-resize';
}
if ($module === 'layout_builder' && isset($libraries['drupal.layout_builder'])) {
$libraries['drupal.layout_builder']['dependencies'][] = 'varbase_editor/ckeditor5';
$libraries['drupal.layout_builder']['dependencies'][] = 'varbase_editor/ckeditor5-media-resize';
}
}
/**
* Implements hook_library_info_alter().
*/
function varbase_editor_filter_info_alter(array &$info) {
if (isset($info['filter_resize_media'])) {
// Replace the class for the 'filter_resize_media' filter
// with 'VarbaseFilterResizeMedia'.
$info['filter_resize_media']['class'] = VarbaseFilterResizeMedia::class;
}
}