You are here

function panels_views_render in Panels 5.2

Render a view as a pane.

1 string reference to 'panels_views_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 751
panels_views.module

Code

function panels_views_render($conf, $panel_args, &$contexts) {
  $pv = panels_views_load($conf['name']);
  if (empty($pv)) {
    return;
  }
  $v = views_get_view($pv->view);

  // no view, we go no further
  if (empty($v)) {
    return;
  }

  // Use clone to make sure this is fresh.
  $view = drupal_clone($v);

  // Check to make sure the user can view this view.
  if (function_exists('views_access') && !views_access($view)) {
    return;
  }
  $args = array();
  if (!empty($pv->contexts)) {
    foreach ($pv->contexts as $id => $data) {
      switch ($data['type']) {
        case 'context':
          $c = array_shift($contexts);
          $args[] = $c->argument;
          break;
        case 'fixed':
          $args[] = $data['fixed'];
          break;
        case 'panel':

          // Only fill $args if a panel arg was passed in that belongs there
          if (array_key_exists($data['panel'], $panel_args)) {
            $args[] = $panel_args[$data['panel']];
          }
          break;
        case 'user':
          $args[] = $conf['arguments'][$id];
          break;
        case 'wildcard':

          // Put in the wildcard.
          $args[] = $view->arguments[$id]['wildcard'] ? $view->arguments[$id]['wildcard'] : '*';
          break;
        case 'none':
        default:

          // Put in NULL.
          // views.module knows what to do with NULL (or missing) arguments
          $args[] = NULL;
          break;
      }
    }
  }
  if ($pv->allow_url_override && $conf['url']) {
    $view->url = $conf['url'];
  }
  else {
    if ($pv->url_override) {
      $view->url = $pv->url;
    }
  }
  $block = new stdClass();
  $block->module = 'views';
  $block->delta = $view->name;
  $view_type = $pv->view_type == 'embed' ? 'page' : $pv->view_type;
  $block->subject = views_get_title($view, $view_type, $args);

  // link to view
  if ($pv->allow_link_to_view && !empty($conf['link_to_view']) || !$pv->allow_link_to_view && $pv->link_to_view) {
    $block->title_link = views_get_url($view, $args);
  }

  // more link
  if ($pv->allow_more_link && !empty($conf['more_link']) || !$pv->allow_more_link && $pv->more_link) {
    $block->more = array(
      'href' => views_get_url($view, $args),
    );
    $view->block_more = FALSE;

    // Alternative "more" link text
    if ($pv->allow_more_text && $conf['more_text']) {
      $block->more['title'] = $conf['more_text'];
    }
    else {
      if ($pv->more_text) {
        $block->more['title'] = $pv->more_text;
      }
    }
  }

  // Turn on pager?
  if ($pv->allow_use_pager) {
    $pager_id = empty($conf['use_pager']) ? 0 : intval($conf['pager_id']) + 1;
  }
  else {
    $pager_id = empty($pv->use_pager) ? 0 : intval($pv->pager_id) + 1;
  }
  $nodes_per_page = $pv->allow_nodes_per_page ? $conf['nodes_per_page'] : $pv->nodes_per_page;
  $offset = $pv->allow_offset ? $conf['offset'] : $pv->offset;
  $stored_feeds = drupal_add_feed();

  // remove any trailing NULL arguments as these are non-args:
  while (count($args) && end($args) === NULL) {
    array_pop($args);
  }
  $block->content = views_build_view($pv->view_type, $view, $args, $pager_id, $nodes_per_page, 0, $offset);
  if ($view->num_rows < $nodes_per_page) {
    unset($block->more);
  }
  if ($pv->allow_feed_icons && !empty($conf['feed_icons']) || !$pv->allow_feed_icons && $pv->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];
      }
    }
  }

  // Provide administrative links
  if (user_access('administer views')) {
    $block->admin_links['update'] = array(
      'title' => t('Edit view'),
      'alt' => t("Edit this view"),
      'href' => $view->vid ? "admin/build/views/{$view->name}/edit" : "admin/build/views/add/{$view->name}",
      'query' => drupal_get_destination(),
    );
  }
  return $block;
}