forked from openeuropa/oe_editorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
oe_editorial.module
60 lines (52 loc) · 1.85 KB
/
oe_editorial.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
<?php
/**
* @file
* OpenEuropa Editorial module.
*/
declare(strict_types = 1);
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
/**
* Implements hook_element_info_alter().
*
* Add a custom process method to the TextFormat form element.
*/
function oe_editorial_element_info_alter(array &$types) {
if (isset($types['text_format'])) {
$types['text_format']['#process'][] = "_oe_editorial_alter_text_format_help";
}
}
/**
* After build callback to alter the Url of the help link on text areas.
*/
function _oe_editorial_alter_text_format_help(&$element, FormStateInterface $form_state, &$complete_form) {
// Replace the format help links with custom ones that point to
// the appropriate help page.
if (isset($element['format']['format'])) {
// Apply custom class to text format select field.
$element['format']['format']['#attributes']['class'][] = 'text-format-filter-list';
foreach ($element['format']['format']['#options'] as $allowed_format_id => $allowed_format_name) {
// We add one link for each of the available format types.
$element['format']['help'][$allowed_format_id] = [
'#type' => 'link',
'#title' => t('About the :format_name format', [':format_name' => $allowed_format_name]),
'#url' => Url::fromRoute('filter.tips', ['filter_format' => $allowed_format_id]),
'#attributes' => [
'class' => [
'filter-help-item',
'filter-help-' . $allowed_format_id,
],
'target' => '_blank',
],
];
}
// Remove the default static link.
unset($element['format']['help']['about']);
$element['format']['help']['#attached']['library'][] = 'oe_editorial/help';
}
// Remove the guidelines area.
if (isset($element['format']['guidelines'])) {
unset($element['format']['guidelines']);
}
return $element;
}