I have a custom install profile and I must programmatically change the body text format on the page content type to full HTML. However, I didn't manage to find how to do it.
How can I do it?
I have a custom install profile and I must programmatically change the body text format on the page content type to full HTML. However, I didn't manage to find how to do it.
How can I do it?
You can do it with hook_element_info_alter
, here is a snippet.
<?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 MODULENAME_element_info_alter(&$type) {
if (isset($type['text_format']['#process'])) {
foreach ($type['text_format']['#process'] as &$callback) {
if ($callback === 'filter_process_format') {
$callback = 'MODULENAME_filter_process_format';
}
}
}
}
/**
* Callback for MODULENAME_element_info_alter().
*/
function MODULENAME_filter_process_format($element) {
$element = filter_process_format($element);
// Change the default text format of the 'field_company_spotlight' field to
// 'Media HTML'.
if ($element['#bundle'] == 'company' && $element['#field_name'] == 'field_company_spotlight') {
$element['format']['format']['#default_value'] = 'media_html';
}
return $element;
}
?>
As THIS post suggests you could try
$form['field_name'][LANGUAGE_NONE][0]['#format'] = 'full_html';
$form['field_name'][LANGUAGE_NONE][0]['#format'] = 'filtered_html';
in your hook_form_alter
or in hook_FORM_ID_alter
Also there is Better Formats module
Better formats is a module to add more flexibility to Drupal's core input format system.
Nikhil M's 2nd answer is best -
$form['field_name'][LANGUAGE_NONE][0]['#format'] = 'full_html';
no need for hook_element_info
you only need one line of code
$result = db_query('UPDATE field_data_body SET body_format='full_html' WHERE bundle
='page');