You are here

function custompage_view_tile in Custom Page 6

Same name and namespace in other branches
  1. 7 custompage_util.inc \custompage_view_tile()

Render a custompage tile for a view.

Parameters

$name: The Name of the view to render.

$title: The title of the tile block, if blank it will use the view title, if you want it explicitly omitted, pass FALSE.

$display_id: The view display id. Blocks are numbered block_<em>N</em> and pages are numbered page_<em>N</em>.

File

./custompage_util.inc, line 14

Code

function custompage_view_tile($name, $title = '', $display_id = 'block_1') {
  $args = func_get_args();
  array_shift($args);

  // remove $name
  if (count($args)) {
    array_shift($args);

    // remove $title
  }
  if (count($args)) {
    array_shift($args);

    // remove $display_id
  }
  $view = views_get_view($name);
  if (empty($view)) {
    return;
  }

  //Use View's title unless something else explicitely indicated or

  //$title === False, which means caller does not want title rendered
  if ($title !== FALSE) {
    if (empty($title)) {
      $display_title = $view->display[$display_id]->display_options['title'];
      $title = $display_title;
      if (empty($display_title)) {

        // if title was not set, use default one.
        $title = $view->display['default']->display_options['title'];
        if (empty($title)) {

          // If title is not set anywhere, use display name
          $title = $view->display[$display_id]->display_title;
        }
      }
    }
  }
  if (!isset($view->override_path)) {
    $view->override_path = $_GET['q'];
  }
  $content = $view
    ->preview($display_id, $args);
  if (!empty($title)) {
    $content = "<div><h2>{$title}</h2>{$content}</div>";
  }
  $editlink = custompage_edit_link('admin/build/views/edit/' . $name);
  $tile = custompage_tile_wrap($content, $editlink);
  return $tile;
}