显示drupal节点编辑预览标题而不仅仅是"预览"

时间:2018-04-04 12:36:22

标签: drupal drupal-7

如何更改要显示的节点预览标题而不仅仅是"预览"?

2 个答案:

答案 0 :(得分:2)

这是一种解决自定义模块中问题的方法

/**
 * 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 );
    }
}

答案 1 :(得分:-2)

这里是如何破解核心来修改标题(快速简便的方法),但更好的方法是通过自定义模块覆盖(也许其他人可以发帖)。

在/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);