Hy!

I have one question about some hooks.
I want to manually output a comments from my own node template file called: node--forumpost.tpl.php.
In hook "mymodule_preprocess_comment_wrapper" I added and changed some values from comments array and if I just render the $content["comments"], then every change can be seen normally.
But if I don't render them with render function, but output them manually from the template file node--forumpost.tpl.php with normal foreach loop, I don't see my attributes added to it in array path $content["comments"]["comments"][$key]["comment_body"]["#object"] because I think that Hook is executed too late.
So hooks "mymodule_preprocess_comment_wrapper" and also "mymodule_preprocess_comment" can get me the list of proper comments, but I can't change the data with these hooks, because i think it's not executed before outputing the node thing.

Thanks

Comments

Jaypan’s picture

Please show:

1) Your code
2) The current output
3) The desired output

sasos90’s picture

Thanks for quick answer.

The hook:

function mymodule_preprocess_comment_wrapper(&$variables)
{
    foreach ($variables["content"]["comments"] as $key => $value) {
        $uid = $value["comment_body"]["#object"]->uid;
        $fid = $value["comment_body"]["#object"]->picture;
        $picturePath = getPicturePath($uid, $fid);
        if (isset($picturePath) === true) {
            $value["comment_body"]["#object"]->picturePath = str_replace("public://", "sites/default/files/styles/thumbnail/public/", $picturePath);
        } else {
            $value["comment_body"]["#object"]->picturePath = drupal_get_path('module', "mymodule") . "/images/nouserpicture.png";
        }
    }
    var_dump($variables["content"]["comments"][22]["comment_body"]["#object"]->picturePath);
}

I go through the comments and add the property picturePath. In the end I can see the proper picturePath from $variables set.

Then in the node--forumpost.tpl.php I vardump this variable:

var_dump($content["comments"]["comments"][23]["comment_body"]["#object"]);die();

And there is no picturePath.
This is the output where picturePath is missing.
http://laravel.io/bin/9vb7M

Thanks

sasos90’s picture

I also tried mymodule_preprocess_comment hook for each comment seperate. And it also doesn't work.