0

I have a node type that can be scheduled. Before the start time the page will redirect to another. This is all custom functionality and is currently working.

Now I need to create a coming soon page to allow the page to be active before the start time but not show any of the details.

I've created a coming soon field in the node and I have the logic set up correctly but I am struggling with the render array.

function MODULE_node_view($node, $view_mode, $langcode) {
  if ($node->type == 'TYPE') {

    // admins see the page no matter what
    if (!user_access('administer site configuration')) {

      // if not started, show coming soon page
      $coming_soon = FALSE;
      if (!STARTED) {
        $coming_soon = field_get_items('node', $node, 'field_coming_soon_body');
        if ($coming_soon) {
          $node->content['body']['#object']->body[$node->language][0]['value'] = $coming_soon[0]['value'];
        }
      }
    }
  }
}

This however still shows the actual body of the page and not the coming soon page. I really want to do this in hook_node_view as well.

How can I go about replacing the content of the page with this single field?

2
  • Instead of reassigning the body's field value, can't you just hide it and show the field_coming_soon_body?
    – typologist
    Oct 28, 2015 at 16:49
  • how do I hide a field in this hook? Oct 28, 2015 at 16:51

1 Answer 1

1

Just hide your body field, if there's a value in your field_coming_soon_body:

    if ($coming_soon) {
      $node->content['body']['#access'] = 0;
    }
1
  • Sure! Glad to help, Scott!
    – typologist
    Oct 28, 2015 at 17:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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