0

I have a module which shows content with the page callback. Here is my page callback (just the relevent code):

function my_page_callback() {
    $build=array();
    $build[] = array(
        '#theme' => 'my_theme',
        '#marker' => 'foo',
        '#data' => ...,
        '#contextual_links' => ...,
    );
    $comment=comment_node_page_additions(node_load(getTargetNodeId()));
    $build[]=$comment['comment_form'];
    return $build;
}

However the function getTargetNodeId() retuns a valid id of a node which is generated unter some conditions with this code:

$node = new StdClass();
$node->nid=42;
$node->vid=42;
$node->uid=1;
$node->type = 'my_type';
$node->status = 1;
$node->title = "Fresh generated";
$node->content['mapping'] = 4711; // some internal magic
$node->comment='2';
$node->language = LANGUAGE_NONE;
$node->body[$node->language][0]['value'] = "This text should nobody read.";
node_save($node);

Even if in the code above the nid and nid are fixed I take care of it the ids are unique.

And here is my code where I render my node:

function module_node_view_alter(&$build) {
    if($build['#bundle']=='my_type') {
        $p=my_page_callback;
        $build['body']=$p[0];
    }
}

drupal output

However the the comment header is generated but the input field is missing. What is the problem?

2

If my_type is a content type defined in the Drupal site, then I would check in admin/structure/types/manage/my_type/comment/fields that you didn't delete the comment body.

screenshot

If this is what happened then the node page changes from what shown in the following first screenshot to what shown in the second screenshot.

before

after

The screenshots has been taken using the user #1 for my test site, which means what shown happens to every user.

The same thing should happen when the content type has been deleted, or it has never existed on the Drupal site.

There could be other reasons:

  • The only input format available in that site is not accessible from the user who is visiting the page your code is outputting. This is not clearly the case if you are using the user #1 to visit the page.
    It also means the site doesn't have the default input format, which is not possible to disable from the user interface. It could be the default input format has been deleted from the database; if this is the case, users would have problems also editing nodes, as the input formats used for comments are the same used for nodes, even if a comment for a node using (for example) full HTML could use plain text, or filtered HTML.
  • The content type has been created programmatically, in a way that didn't cause hook_node_type_insert() to be invoked. If this is the case, then the Comment module doesn't have the possibility of adding the comment body field, which is done using the following function.

    function comment_node_type_insert($info) {
      _comment_body_field_create($info);
    }
    

protected by kiamlaluno Jul 26 '12 at 9:20

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.