-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspecify_text_format_for_field.inc
More file actions
37 lines (31 loc) · 1009 Bytes
/
specify_text_format_for_field.inc
File metadata and controls
37 lines (31 loc) · 1009 Bytes
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
<?php
/**
* This code goes in a custom module. It will set the default text format
* for data entry on a specific field. For when you have a wysiwyg field
* that you want users to use a specific text format with.
*/
/**
* Implements hook_element_info_alter().
*/
function my_module_element_info_alter(&$type) {
if (isset($type['text_format']['#process'])) {
foreach ($type['text_format']['#process'] as &$callback) {
if ($callback === 'filter_process_format') {
$callback = 'my_module_set_text_format';
}
}
}
}
/**
* Set a specific text format for content entry on certain fields.
*/
function my_module_set_text_format($element) {
$element = filter_process_format($element);
if (empty($element['#bundle']) || empty($element['#field_name'])) {
return $element;
}
if ($element['#bundle'] == 'page' && $element['#field_name'] == 'field_my_long_text') {
$element['format']['format']['#default_value'] = 'my_text_format_name';
}
return $element;
}