2015-10-08
I needed a full HTML field in one of my content types in Drupal 7 to load with WYSIWYG disabled by default. The solution turned out to be a simple custom module. See the full code below for a complete solution.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implement hook_element_info_alter() | |
* Enable custom processing of a field in authoring form before it is rendered to the user | |
* | |
* @param array $elements | |
*/ | |
function my_module_element_info_alter(&$elements) { | |
array_unshift($elements['text_format']['#pre_render'], 'my_module_process_text_format'); | |
} | |
/** | |
* Test if there is a 'summary' in the element or the field name is 'field_map'. | |
* Then tell ckeditor to not load the wysiwyg editor. | |
* Also disalbe wysiwyg on a field 'field_map' field | |
* | |
* @param boolean $element | |
* @return boolean | |
*/ | |
function my_module_process_text_format($element) { | |
if (!empty($element['summary'])) { | |
$element['summary']['#wysiwyg'] = FALSE; | |
} | |
if($element['#field_name'] == 'field_map') { | |
$element['value']['#wysiwyg'] = FALSE; | |
} | |
return $element; | |
} | |
/** | |
* When authoring 'event' nodes, set format of the field 'field_map' to Full HTML | |
* | |
*/ | |
function my_module_form_alter(&$form, &$form_state, $form_id) { | |
if ($form_id == 'event_node_form') { | |
$form['field_map']['und'][0]['#format'] = 'full_html'; | |
} | |
return $form; | |
} |