1

I created a content type that is used to display a list of videos hosted on brightcove. I have a module that is setting a cookie for the anonymous user when they watch one. My end goal is to display a viewed/unviewed icon for the user on the list.

I have all the data I need in the cookie. I just need to create a module that reads the cookie data and edits the render array for the content type. The issue is I am not sure how to add new values to that content type's render array. Is there a hook I can use to get access to the specific content type to add a key/value for viewed/unviewed? This is for drupal 7.

Thanks for the help.

2

hook_node_view() was made for exactly that:

Act on a node that is being assembled before rendering.

e.g.

function MYMODULE_node_view($node, $view_mode, $langcode) {
  if ($node->type == 'my_type' && $view_mode == 'full') {
    if (in_array($node->nid, $_SESSION['viewed_videos'])) {
      $node->content['viewed'] = array(
        '#markup' => t('You have viewed this video'),
        '#weight' => 10,
      );
    }
  }
}
| improve this answer | |
  • looks good to me. I will be playing with this. Thanks! – joshmmo May 10 '13 at 2:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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