0

I tried hook_views_pre_render but it's not acting as I would have expected. What I'm doing is taking the view data after it has been executed, looking at the result, and then changing the result.

function field_collection_views_views_pre_render(&$view) {
  if ($view->name == 'my_fc_slideshow') {
    $current_page = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
    $parsed_url = parse_url($current_page);
    $path_components = explode('/', $parsed_url['path']);
    // Is this the drafted or published revision?
    if ($path_components[3] != 'draft') {
      dpm($view);
      $results = &$view->result;
      $node = menu_get_object();
      foreach ($results as $delta => $result) {
        $correct_fc_vid = $node->field_carousel_slides['und'][$delta]['revision_id'];
        $published_fc = entity_revision_load('field_collection_item', $correct_fc_vid);
        $view->result[$delta]->_field_data['item_id']['entity'] = $published_fc;
        dpm($view);
      }
    }
  }
}

When I dpm the view before and after the changes it does show the correct information in result, however what is on the page does not reflect the change.

The reason I am doing this is because field collection views will not show the published revision, only the latest one, be it a draft or not. When making a normal node view, it will only show the published version. On both views, any filter for revision does not take unless it's either the published or latest revision depending on which view you're in.

I have tried solving this with patches on field collection, workbench moderation, and field collection views, and even a sandbox module, but none of these solutions has worked.

So how can I get hook_views_pre_render to work as I need, or, is there a better views hook to do this with?

  • Perhaps it is a dumb question, but could you try without the ampersand here: $results = &$view->result; – Djouuuuh Oct 17 '14 at 14:12
  • try this hook - hook_views_post_execute – Petro Popelyshko Oct 17 '14 at 14:20
  • @Djouuuuh same result; object has the right data, output does not – CR47 Oct 17 '14 at 14:33
  • @neok - this produces the same result as hook_views_pre_render unfortunately – CR47 Oct 17 '14 at 14:48

Your Answer

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

Browse other questions tagged or ask your own question.