显示 drupal 节点编辑预览标题而不仅仅是 "Preview"
Display drupal node edit preview title instead of just "Preview"
如何更改要显示的节点预览标题而不仅仅是 "Preview"?
这里介绍了如何破解核心以修改标题(快速简便的方法),但更好的办法是通过自定义模块进行覆盖(也许其他人可以 post 请)。
在/modules/node/node.pages.inc中添加$node->title
在drupal_set_title(t('Preview'), PASS_THROUGH);
中
像这样:
// Display a preview of the node.
if (!form_get_errors()) {
$cloned_node->in_preview = TRUE;
$output = theme('node_preview', array('node' => $cloned_node));
unset($cloned_node->in_preview);
}
drupal_set_title(t('Preview: '.$node->title), PASS_THROUGH);
这是解决您自定义模块中问题的方法
/**
* implements hook_form_BASE_FORM_ID_alter
* the form id that will build the node preview is page_node_form
* @param $form
* @param $form_state
*/
function yourmodulename_form_page_node_form_alter( $form, $form_state ){
if( !empty( $form_state['node']->in_preview ) ){
// security hint: do not pass the PASS_THROUGH param to the drupal_set_title
// because the node title may contain some xss. Without this parameter the
// drupal_set_title will check for xss and remove them if present
drupal_set_title(t('Preview') . ' ' . $form['#node']->title );
}
}
如何更改要显示的节点预览标题而不仅仅是 "Preview"?
这里介绍了如何破解核心以修改标题(快速简便的方法),但更好的办法是通过自定义模块进行覆盖(也许其他人可以 post 请)。
在/modules/node/node.pages.inc中添加$node->title
在drupal_set_title(t('Preview'), PASS_THROUGH);
像这样:
// Display a preview of the node.
if (!form_get_errors()) {
$cloned_node->in_preview = TRUE;
$output = theme('node_preview', array('node' => $cloned_node));
unset($cloned_node->in_preview);
}
drupal_set_title(t('Preview: '.$node->title), PASS_THROUGH);
这是解决您自定义模块中问题的方法
/**
* implements hook_form_BASE_FORM_ID_alter
* the form id that will build the node preview is page_node_form
* @param $form
* @param $form_state
*/
function yourmodulename_form_page_node_form_alter( $form, $form_state ){
if( !empty( $form_state['node']->in_preview ) ){
// security hint: do not pass the PASS_THROUGH param to the drupal_set_title
// because the node title may contain some xss. Without this parameter the
// drupal_set_title will check for xss and remove them if present
drupal_set_title(t('Preview') . ' ' . $form['#node']->title );
}
}