Answers:
您可以使用来实现hook_element_info_alter
,这是一个代码段。
<?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;
}
?>
作为本后建议你可以试试
$form['field_name'][LANGUAGE_NONE][0]['#format'] = 'full_html';
$form['field_name'][LANGUAGE_NONE][0]['#format'] = 'filtered_html';
在你hook_form_alter
或在hook_FORM_ID_alter
也有更好的格式模块
更好的格式是为Drupal的核心输入格式系统增加更多灵活性的模块。
Nikhil M的第二个答案是最好的-
$form['field_name'][LANGUAGE_NONE][0]['#format'] = 'full_html';
无需hook_element_info
您只需要一行代码
$ result = db_query('UPDATE field_data_body SET body_format ='full_html'WHERE bundle
='page');