You are here

function panels_views_panes_render in Panels 6.2

Render a view pane

1 string reference to 'panels_views_panes_render'
panels_views_panels_content_types in panels_views/panels_views.module
Implementation of hook_panels_content_types()

File

panels_views/panels_views.module, line 376
panels_views.module

Code

function panels_views_panes_render($subtype, $conf, $panel_args, $contexts) {
  if (!is_array($contexts)) {
    $contexts = array(
      $contexts,
    );
  }
  list($name, $display) = explode('-', $subtype);
  $view = views_get_view($name);
  if (empty($view)) {
    return;
  }
  $view
    ->set_display($display);
  if (!$view->display_handler
    ->access($GLOBALS['user'])) {
    return;
  }
  if (!$view->display_handler
    ->access($GLOBALS['user'])) {
    return;
  }
  $args = array();
  $arguments = $view->display_handler
    ->get_option('arguments');
  foreach ($view->display_handler
    ->get_argument_input() as $id => $argument) {
    switch ($argument['type']) {
      case 'context':
        $c = array_shift($contexts);
        $args[] = $c->argument;
        break;
      case 'fixed':
        $args[] = $argument['fixed'];
        break;
      case 'panel':
        $args[] = $panel_args[$argument['panel']];
        break;
      case 'user':
        $args[] = isset($conf['arguments'][$id]) ? $conf['arguments'][$id] : NULL;
        break;
      case 'wildcard':

        // Put in the wildcard.
        $args[] = isset($arguments[$id]['wildcard']) ? $arguments[$id]['wildcard'] : '*';
        break;
      case 'none':
      default:

        // Put in NULL.
        // views.module knows what to do with NULL (or missing) arguments
        $args[] = NULL;
        break;
    }
  }

  // remove any trailing NULL arguments as these are non-args:
  while (count($args) && end($args) === NULL) {
    array_pop($args);
  }
  $view
    ->set_arguments($args);
  if ($allow['path_override'] && !empty($conf['path'])) {
    $view->display_handler
      ->set_option('path', $conf['path']);
  }
  $block = new stdClass();
  $block->module = 'views';
  $block->delta = $view->name . $display;
  $block->subject = $view
    ->get_title();
  if ($allow['link_to_view'] && !empty($conf['link_to_view']) || !$allow['link_to_view'] && $view->display_handler->get_option['link_to_view']) {
    $block->title_link = $view
      ->get_url();
  }

  // more link
  if ($allow['more_link'] && !empty($conf['more_link']) || !$allow['more_link'] && $view->display_handler->get_option['more_link']) {
    $block->more = array(
      'href' => $view
        ->get_url(),
    );
    $view->display_handler
      ->set_option('use_more', FALSE);

    // make sure the view runs the count query so we know whether or not the more link
    // applies.
    $view->get_total_rows = TRUE;
  }
  if ($allow['use_pager']) {
    $view->display_handler
      ->set_option('use_pager', $conf['use_pager']);
    $view->display_handler
      ->set_option('pager_element', $conf['pager_id']);
  }
  if ($allow['items_per_page']) {
    $view->display_handler
      ->set_option('items_per_page', $conf['items_per_page']);
  }
  if ($allow['offset']) {
    $view->display_handler
      ->set_option('offset', $conf['offset']);
  }
  $stored_feeds = drupal_add_feed();
  $block->content = $view
    ->preview();
  if ($view->total_rows <= $view->display_handler
    ->get_option('items_per_page')) {
    unset($block->more);
  }
  if ($allow['feed_icons'] && !empty($conf['feed_icons']) || !$allow['feed_icons'] && $view->display_handler->get_option['feed_icons']) {
    $new_feeds = drupal_add_feed();
    if ($diff = array_diff(array_keys($new_feeds), array_keys($stored_feeds))) {
      foreach ($diff as $url) {
        $block->feeds[$url] = $new_feeds[$url];
      }
    }
  }
  return $block;
}