You are here

function eva_get_views in EVA: Entity Views Attachment 7

Same name and namespace in other branches
  1. 8 eva.module \eva_get_views()

Gets a list of views and displays attached to specific entities.

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

Parameters

string|null $type: (optional) The entity type we want to retrieve views for. If NULL is specified, views for all entity types will be returned. Defaults to NULL.

bool $reset: (optional) Force a rebuild of the data. Defaults to FALSE.

Return value

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

3 calls to eva_get_views()
eva_entity_view_alter in ./eva.module
Implements hook_entity_view_alter().
eva_field_attach_form in ./eva.module
Implements hook_field_attach_form().
eva_field_extra_fields in ./eva.module
Implements hook_field_extra_fields().
2 string references to 'eva_get_views'
eva_modules_disabled in ./eva.module
Implements hook_modules_disabled().
eva_modules_enabled in ./eva.module
Implements hook_modules_enabled().

File

./eva.module, line 192

Code

function eva_get_views($type = NULL, $reset = FALSE) {
  $used_views =& drupal_static(__FUNCTION__);
  if (!isset($used_views) || $reset) {
    views_include('cache');

    // If we're not resetting, check the Views cache.
    if (!$reset) {
      $cache = views_cache_get("eva");
      if (isset($cache->data)) {
        $used_views = $cache->data;
      }
    }

    // If it's still empty rebuild it.
    if (!isset($used_views)) {
      $used_views = array();

      // Trigger a rebuild of the views object cache, which may not be fully loaded.
      ctools_include('export');
      ctools_export_load_object_reset('views_view');

      // Build and cache the data, both in the DB and statically.
      $views = views_get_applicable_views('uses hook entity view');
      foreach ($views as $data) {
        list($view, $display_id) = $data;
        $view_entity = $view->display_handler
          ->get_option('entity_type');

        // Initialize handlers, to determine if the view uses exposed filters.
        $view
          ->init_handlers();
        $used_views[$view_entity][] = array(
          'name' => $view->name,
          'title' => 'EVA: ' . $view
            ->get_human_name() . ' - ' . $view->display[$display_id]->display_title,
          'display' => $display_id,
          'show_on' => $view->display_handler
            ->get_option('show_on'),
          'bundles' => $view->display_handler
            ->get_option('bundles'),
          'exposed form' => $view->display_handler
            ->uses_exposed(),
          'exposed form split' => $view->display_handler
            ->get_option('exposed_form_as_field'),
        );
        $view
          ->destroy();
      }
      views_cache_set("eva", $used_views);
    }
  }

  // Now spit back the data.
  if (isset($type) & isset($used_views)) {
    return isset($used_views[$type]) ? $used_views[$type] : array();
  }
  else {
    return isset($used_views) ? $used_views : array();
  }
}