You are here

function hosting_site_views_pre_build in Hosting 7.3

Same name and namespace in other branches
  1. 7.4 site/includes/views/hosting_site.views.inc \hosting_site_views_pre_build()

Implements hook_views_pre_build().

File

site/includes/views/hosting_site.views.inc, line 266
Hosting site views integration.

Code

function hosting_site_views_pre_build(&$view) {
  if ($view->name == 'hosting_site_list') {
    switch ($view->current_display) {
      case 'page_sites':

        // Only allow VBO for admins.
        if (!user_access('administer sites')) {
          unset($view->field['views_bulk_operations']);
          unset($view->display_handler->handlers['field']['views_bulk_operations']);
        }
        break;
      case 'block_sites':

        // Rather than maintain separate views/displays for each hosting
        // content type, we alter the view to remove all but the relevant
        // contextual filters (arguments) here.
        // @see: hosting_site_block_view_alter().
        if ($node = menu_get_object()) {
          if (in_array($node->type, array(
            'platform',
            'server',
            'client',
            'package',
          ))) {
            foreach ($view->argument as $name => $arg) {
              if (!in_array($node->type, $arg->options['validate_options']['types'])) {
                unset($view->argument[$name]);
                unset($view->display_handler->handlers['argument'][$name]);
                unset($view->display_handler->display->display_options['arguments'][$name]);
                unset($view->display_handler->options['arguments'][$name]);
              }
            }

            // Only allow VBO for admins.
            if (!user_access('administer sites')) {
              unset($view->field['views_bulk_operations']);
              unset($view->display_handler->handlers['field']['views_bulk_operations']);
            }
          }
        }
        break;
    }
  }
}