2

I have a content type for publishing a node once a week (type A) - on Saturday night/Sunday morning - that needs to show, as an attachment, a list of some other nodes (type B) that go live daily during the week (one node a day) I have a view that puts together nodes of type B for 6 days of week - Monday through Saturday, so I have a filter on Post Date between 'last Sunday' and 'now' and I limit the number of nodes to 6. Then I use Viewfield to show the view of nodes B on content type A - and it all seems to work, but! (there are always those 'buts', right??) - I want to 'freeze' the View's content at the time of publishing - so if somebody will click on the type A node two weeks from now, the list of the type B nodes should be relevant to the week the type A node was published on - so, I need to somehow filter the type B nodes view using an "external date" parameter How do I do that?

2

I thought about the relationship angle and couldn't find one but I have been known to be blind in the past to things in front of me and instead went the hook_views_pre_view() route...

function YOUR_CUSTOM_MODULE_views_pre_view(&$view, &$display_id, &$args) {

  if ($view->name=='last_sunday_and_now') { // or whatever your View is named

    // see what we have to work with...

    $filters = $view->display_handler->get_option('filters');
    drupal_set_message('<pre>Before: ' . print_r($filters, TRUE) . '</pre>');

    // here on my box it is 'date_filter' so let's change things up

    $filters['date_filter']['default_date'] = // set this to whatever you want instead of "Last Sunday"
    $filters['date_filter']['default_to_date'] = // set this to whatever you want instead of "now"

    $overrides = array();
    $overrides['filters'] = $filters;

    foreach ($overrides as $option => $value) {
      $view->display_handler->override_option($option, $value);
    }

    // let's see what we have...

    $filters = $view->display_handler->get_option('filters');
    drupal_set_message('<pre>After: ' . print_r($filters, TRUE) . '</pre>');

  }

}

It's up to you to define the logic of what to set the dates to, but if this is sitting on a node, you can grab the post date of it via menu_get_object() pretty readily and then use any of the various date and time functions to create the dates.

  • thanks! this looks like a solid straight-forward way to do it, definitely will be my plan B: I'm still trying to solve it without code writing - with the relationships... no progress yet. – Oleg Ivanov Dec 20 '13 at 3:18
1

It sounds like you need a relationship from parent node A, the publish date to be the filter for Nodes of type B. I think Views can handle this use-case out of the box.

So add like a contextual filter for the parent node A NID in your View for B stuff -- and then basically keep the rest of your view listing for type B the same.

Viewfield should be able to accept an argument for the View as the type A parent NID that was published.

  • I'm at loss here...I added a relationship - Content Type B now has a Node Reference field that references Type A (is that what are you talking about?). On Content A, its Viewfield that renders the View of Nodes B, passes [node:nid], [node:created] args. But how do I add the context. filter for "parent NID"?? and BTW - I have Clean URLs on, so - not much is coming in the URL. And how do I use the A's publish date to filter on Bs? I don't see such option... can you give some more details please? – Oleg Ivanov Dec 20 '13 at 4:10

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.