Skip to content

Instantly share code, notes, and snippets.

@makbeta
Created October 8, 2015 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save makbeta/9d807e2c96217ad27191 to your computer and use it in GitHub Desktop.
Save makbeta/9d807e2c96217ad27191 to your computer and use it in GitHub Desktop.
D7 modules that sets default format for a field; disables Wisiwyg editor on a set field & summary
<?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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment