Skip to content

Instantly share code, notes, and snippets.

@lhuria94
Created July 4, 2017 12:28
Show Gist options
  • Save lhuria94/c6b44c40a89ffe5e02915b7d26c56cd2 to your computer and use it in GitHub Desktop.
Save lhuria94/c6b44c40a89ffe5e02915b7d26c56cd2 to your computer and use it in GitHub Desktop.
<?php
/**
* Implements hook_element_info_alter().
*
* Sets the text format processor to a custom callback function.
* This code is taken from the Better Formats module.
*/
function module_element_info_alter(&$type) {
if (isset($type['text_format']['#process'])) {
foreach ($type['text_format']['#process'] as &$callback) {
if ($callback === 'filter_process_format') {
$callback = 'default_text_format_filter_process_format';
}
}
}
}
/**
* Callback for MODULENAME_element_info_alter().
*/
function module_text_format_filter_process_format($element) {
$element = filter_process_format($element);
// Change input format to "Filtered HTML" for body fields of article nodes
if ($element['#bundle'] == 'bundle_name' && $element['#field_name'] == 'field_name') {
$element['format']['format']['#default_value'] = 'format_name';
}
return $element;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment