function views_block_view

3.x views.module views_block_view($delta)

Implement hook_block_view().

File

./views.module, line 662
Primarily Drupal hooks and global API functions to manipulate views.

Code

function views_block_view($delta) {
  $start = microtime(TRUE);
  // if this is 32, this should be an md5 hash.
  if (strlen($delta) == 32) {
    $hashes = variable_get('views_block_hashes', array());
    if (!empty($hashes[$delta])) {
      $delta = $hashes[$delta];
    }
  }

  // This indicates it's a special one.
  if (substr($delta, 0, 1) == '-') {
    list($nothing, $type, $name, $display_id) = explode('-', $delta);
    // Put the - back on.
    $type = '-' . $type;
    if ($view = views_get_view($name)) {
      if ($view->access($display_id)) {
        $view->set_display($display_id);
        if (isset($view->display_handler)) {
          $output = $view->display_handler->view_special_blocks($type);
          // Before returning the block output, convert it to a renderable
          // array with contextual links.
          views_add_block_contextual_links($output, $view, $display_id, 'special_block_' . $type);
          $view->destroy();
          return $output;
        }
      }
      $view->destroy();
    }
  }

  // If the delta doesn't contain valid data return nothing.
  $explode = explode('-', $delta);
  if (count($explode) != 2) {
    return;
  }
  list($name, $display_id) = $explode;
  // Load the view
  if ($view = views_get_view($name)) {
    if ($view->access($display_id)) {
      $output = $view->execute_display($display_id);
      // Before returning the block output, convert it to a renderable array
      // with contextual links.
      views_add_block_contextual_links($output, $view, $display_id);
      $view->destroy();
      return $output;
    }
    $view->destroy();
  }
}