Skip to main content
added 977 characters in body
Source Link
Jimajamma
  • 17.1k
  • 1
  • 28
  • 35

ADDITION/CORRECTION:

For Views in Drupal7, the cache is built up by Ctools and its _ctools_export_get_defaults() function that is defined in .../ctools/includes/export.inc. It is called many ways down the line from views_get_all_views():

function views_get_all_views($reset = FALSE) {
  ctools_include('export');
  return ctools_export_crud_load_all('views_view', $reset);
}

where ctools_export_crud_load_all() eventually calls it. The kicker for grep'ing around to find this is that it uses $function = $module . '_' . $export['default hook']; to cycle through all the modules that implement the hook, and that is defined in views.install:

'default hook' => 'views_default_views',

so it certainly took a bit to find but it is a nice api way to allow all sorts of modules to export objects in a defined fashion. I won't include the code here as it's a bit more verbose than the D6 version below but do let me know if you need any other help on this.

MY BAD: This is The following for D6....D7 answer on the wayabove but I'll keep this in here if anyone in D6land ever needs an answer:

MY BAD: This is for D6....D7 answer on the way but I'll keep this in here if anyone in D6land ever needs an answer:

ADDITION/CORRECTION:

For Views in Drupal7, the cache is built up by Ctools and its _ctools_export_get_defaults() function that is defined in .../ctools/includes/export.inc. It is called many ways down the line from views_get_all_views():

function views_get_all_views($reset = FALSE) {
  ctools_include('export');
  return ctools_export_crud_load_all('views_view', $reset);
}

where ctools_export_crud_load_all() eventually calls it. The kicker for grep'ing around to find this is that it uses $function = $module . '_' . $export['default hook']; to cycle through all the modules that implement the hook, and that is defined in views.install:

'default hook' => 'views_default_views',

so it certainly took a bit to find but it is a nice api way to allow all sorts of modules to export objects in a defined fashion. I won't include the code here as it's a bit more verbose than the D6 version below but do let me know if you need any other help on this.

MY BAD: The following for D6....D7 answer above but I'll keep this in here if anyone in D6land ever needs an answer:

added 120 characters in body
Source Link
Jimajamma
  • 17.1k
  • 1
  • 28
  • 35

MY BAD: This is for D6....D7 answer on the way but I'll keep this in here if anyone in D6land ever needs an answer:

If what you are asking is where does Views build up its cache of default views, it does this via the _views_discover_default_views() function found in .../views/includes/cache.inc:

If what you are asking is where does Views build up its cache of default views, it does this via the _views_discover_default_views() function found in .../views/includes/cache.inc:

MY BAD: This is for D6....D7 answer on the way but I'll keep this in here if anyone in D6land ever needs an answer:

If what you are asking is where does Views build up its cache of default views, it does this via the _views_discover_default_views() function found in .../views/includes/cache.inc:

Source Link
Jimajamma
  • 17.1k
  • 1
  • 28
  • 35

If what you are asking is where does Views build up its cache of default views, it does this via the _views_discover_default_views() function found in .../views/includes/cache.inc:

/**
 * Scan all modules for default views and rebuild the default views cache.
 *
 * @return An associative array of all known default views.
 */
function _views_discover_default_views($reset = FALSE) {
  static $cache = NULL;

  if (!isset($cache) || $reset) {
    $index = views_cache_get('views_default_views_index', TRUE);

    // Retrieve each cached default view
    if (!$reset && isset($index->data) && is_array($index->data)) {
      $cache = array();
      foreach ($index->data as $view_name) {
        $data = views_cache_get('views_default:' . $view_name, TRUE);
        if (isset($data->data) && is_object($data->data)) {
          $cache[$view_name] = $data->data;
        }
      }
    }
    // If missing index, rebuild the cache
    else {
      views_include_default_views();
      $cache = array();

      foreach (module_implements('views_default_views') as $module) {
        $results = call_user_func($module . "_views_default_views");
        if (!empty($results) && is_array($results)) {
          foreach($results as $name => $view) {
            // Only views with a sufficiently high api version are eligible.
            if (!empty($view->api_version) && $view->api_version >= 2) {
              // Do not cache dead handlers.
              $view->destroy();
              if (!isset($cache[$name])) {
                $cache[$name] = $view;
              }
              else {
                watchdog('view', "View name '@name' is already taken", array('@name' => $name), WATCHDOG_ERROR);
              }
            }
          }
        }
      }

      // Allow modules to modify default views before they are cached.
      drupal_alter('views_default_views', $cache);

      // Cache the index
      $index = array_keys($cache);
      views_cache_set('views_default_views_index', $index, TRUE);

      // Cache each view
      foreach ($cache as $name => $view) {
        views_cache_set('views_default:' . $name, $view, TRUE);
      }
    }
  }

  return $cache;
}