You are here

function panels_views_legacy_render in Panels 5.2

Output function for the 'views' content type.

Outputs a views based on the module and delta supplied in the configuration.

1 string reference to 'panels_views_legacy_render'
panels_views_legacy_panels_content_types in panels_views_legacy/panels_views_legacy.module
Implementation of hook_panels_content_types()

File

panels_views_legacy/panels_views_legacy.module, line 60
panels_views_legacy.module

Code

function panels_views_legacy_render($conf, $panel_args, $contexts) {
  if (!is_array($contexts)) {
    $contexts = array(
      $contexts,
    );
  }

  // Use clone to make sure this is fresh.
  $v = views_get_view($conf['view']);
  if ($v) {
    $view = drupal_clone($v);
    if (function_exists('views_access') && !views_access($view)) {
      return NULL;
    }
    $arguments = explode('/', $_GET['q']);
    $args = $conf['args'];
    foreach ($arguments as $id => $arg) {
      $args = str_replace("%{$id}", $arg, $args);
    }
    foreach ($panel_args as $id => $arg) {
      $args = str_replace("@{$id}", $arg, $args);
    }
    $args = preg_replace(',/?(%\\d|@\\d),', '', $args);
    $args = $args ? explode('/', $args) : array();
    if ($conf['panel_args'] && is_array($panel_args)) {
      $args = array_merge($panel_args, $args);
    }
    if (is_array($conf['context'])) {
      foreach ($conf['context'] as $count => $cid) {
        if ($cid != 'any' && !empty($contexts[$count]) && isset($contexts[$count]->argument)) {
          array_splice($args, $count, 0, array(
            $contexts[$count]->argument,
          ));
        }
      }
    }
    if ($conf['url']) {
      $view->url = $conf['url'];
    }
    $block = new stdClass();
    $block->module = 'views';
    $block->delta = $view->name;
    $view_type = $conf['type'] == 'embed' ? 'page' : $conf['type'];
    $block->subject = views_get_title($view, $view_type);
    if (!empty($conf['link_to_view'])) {
      $block->title_link = views_get_url($view, $args);
    }
    if (!empty($conf['more_link'])) {
      $block->more = array(
        'href' => views_get_url($view, $args),
      );
      $view->block_more = FALSE;
    }
    $pager_id = empty($conf['use_pager']) ? 0 : intval($conf['pager_id']);
    $stored_feeds = drupal_add_feed();
    $block->content = views_build_view($conf['type'], $view, $args, $pager_id, intval($conf['nodes_per_page']), 0, intval($conf['offset']));
    if (!empty($conf['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];
        }
      }
    }
    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;
}