You are here

function views_attach_get_node_views in Views attach 7.2

Same name and namespace in other branches
  1. 6.2 views_attach.module \views_attach_get_node_views()
  2. 6 views_attach.module \views_attach_get_node_views()

Get a list of views and displays attached to the specified category.

This function will cache its results into the views cache, so it gets cleared by Views appropriately.

Parameters

$type: The node type for which we want a list of view information.

$mode: The display mode to check for. Possible values are "full" and "teaser". If NULL, return information for all modes.

Return value

An array of view name/display name values, or an empty array().

3 calls to views_attach_get_node_views()
views_attach_content_extra_fields in ./views_attach.module
Implementation of hook_content_extra_fields.
views_attach_form_alter in ./views_attach.module
Implementation of hook_form_alter().
views_attach_nodeapi in ./views_attach.module
Implementation of hook_nodeapi().

File

./views_attach.module, line 182

Code

function views_attach_get_node_views($type, $mode = NULL) {
  static $used_views = array();
  if (empty($used_views)) {
    views_include('cache');
    $cache = views_cache_get("views_attach:nodes");
    if (isset($cache->data)) {
      $used_views = $cache->data;
    }
    else {

      // Build and cache the data, both in the DB and statically.
      $views = views_get_applicable_views('uses hook nodeapi');
      foreach ($views as $data) {
        list($view, $display_id) = $data;
        foreach ($view->display_handler
          ->get_option('types') as $type_to_use) {
          $modes = $view->display_handler
            ->get_option('modes');
          foreach ($modes as $value) {
            $used_views[$type_to_use][$value][] = array(
              'name' => $view->name,
              'display' => $display_id,
              'title' => $view
                ->get_title(),
            );
          }
        }
        $view
          ->destroy();
      }
      views_cache_set("views_attach:nodes", $used_views);
    }
  }
  if (is_null($mode)) {
    return isset($used_views[$type]) ? $used_views[$type] : array();
  }
  else {
    return isset($used_views[$type][$mode]) ? $used_views[$type][$mode] : array();
  }
}