The code example given for hook_views_pre_view() claims that you can change the display by simply changing $display_id:

function hook_views_pre_view(&$view, &$display_id, &$args) {
  // Change the display if the acting user has 'administer site configuration'
  // permission, to display something radically different.
  // (Note that this is not necessarily the best way to solve that task. Feel
  // free to contribute another example!)
  if (
    $view->name == 'my_special_view' &&
    user_access('administer site configuration') &&
    $display_id == 'public_display'
  ) {
    $display_id = 'private_display';
  }
}

But this is not correct, you have to call $view->set_display() to do this.

This documentation issue only affects 7.x-3.x, in 8.x a different example is used.

Comments

pfrenssen’s picture

Issue summary: View changes
pfrenssen’s picture

Status: Active » Needs review
StatusFileSize
new383 bytes
moonray’s picture

Status: Needs review » Reviewed & tested by the community

Ran into this issue. Patched example works.

dawehner’s picture

Status: Reviewed & tested by the community » Fixed

Next time just ping me and it won't be forgotten.

pfrenssen’s picture

Status: Fixed » Reviewed & tested by the community

It has not been committed yet to 7.x-3.x. Did you forget to push? :)

  • pfrenssen authored dbc703c on 7.x-3.x
    Issue #2308885 by pfrenssen: Wrong example in documentation for...
dawehner’s picture

Status: Reviewed & tested by the community » Fixed

Pushed now

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.