开发者

show node when editing a comment

开发者 https://www.devze.com 2023-02-25 10:08 出处:网络
When editing a comment, the comment is shown alone, without its associated node. I found no solution to show the comment editing form together with the node on the same page. When creating a new com开

When editing a comment, the comment is shown alone, without its associated node. I found no solution to show the comment editing form together with the node on the same page. When creating a new com开发者_如何学编程ment, I can configure Drupal to show both on the same page. I thought about modifying the comment form by a template file and include the node into this template file, but I think, this is an ugly and difficult solution.

thanks in advance for any hints, Gregor Hyneck


You cannot configure it as such. But if you are willing to create a module, the code needed is simple:

showcomment_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == "comment_form") { #you might want to make this test smarter, to avoid admin-interface and general comment-form from changing.
    $form['node_preview'] = array(
      '#type' => 'markup',
      '#markup' => theme('node', $form['#node']),
    );
  }  
}

Obviously, your production code will need a few extra tests to avoid the node from rendering on each comment-form. And you probably don't want the generic theme_node, but a custom one, rendering only the essentials of the node (title+teaser or so).

0

精彩评论

暂无评论...
验证码 换一张
取 消