hook_views_default_views returns an array of $views objects. Immediately after that function has finished, where does it send the $views object it returns?

Obviously that array is passed to another function where it's iterated over and something is done with the data. That's what I want to investigate - what views is doing with the data.

I checked views.module and other files and saw a lot of references to ctools functions, but then got a little lost.

What and where is the function that handles that return value?

  • That function could be called from a multitude of places, though I'm not sure. You are going to be hard pressed to find someone to give you a full blow by blow on where this function is called and exactly what happens. You are probably better just telling us what you are trying to achive and the problems you are having.
    – 2pha
    Mar 18, 2013 at 12:19
  • I'm investigating a performance issue. As the number of views objects added to that return array increases, performance decreases. When that function finishes, views then starts to iterate over the array to save it to the database. This is the function I am trying to find. As it currently works, I am getting timeout and memory issues that's specifically related to the next step in the process after views_default_views returns the array from my custom module.
    – blue928
    Mar 18, 2013 at 12:43

1 Answer 1



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) {
  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:

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 {
      $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.
              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;
  • Looking in the Views 3 cache.inc file, this function is not there. Nor is views_include_default_views() which is in the else statement in the above function. Also, neither of these is listed in the drupal views 7 api online. What drupal version / views version is this from?
    – blue928
    Mar 18, 2013 at 15:14
  • Yikes. My apologies, I thought I'd cd'ed to the drupal 7 directory but instead was looking at d6 v3. It appears on first glance that d7's Views uses Ctools' object cache for this. I'll investigate further and get back with you.
    – Jimajamma
    Mar 18, 2013 at 19:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.