You are here

function eva_get_views in EVA: Entity Views Attachment 8

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

Get a list of views and displays attached to speficic entities.

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

Parameters

$type: The entity type we want to retrieve views for. If NULL is specified, views for all entity types will be returned.

$reset: Force a rebuild of the data.

Return value

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

3 calls to eva_get_views()
eva_entity_extra_field_info in ./eva.module
Implements hook_entity_extra_field_info() to add the view fields to relevant entities
eva_entity_view in ./eva.module
Implements hook_entity_view()
_eva_clear_detached in ./eva.module
An extra field no longer present is not automatically removed from a display config Run through all entity displays and clear out views that shouldn't be there this should be called at Views save and module install/remove $remove_one: force…
1 string reference to 'eva_get_views'
_eva_reset in ./eva.module
Cache clearing helper function Reset the static cache in case any of the disabled modules implemented an eva view

File

./eva.module, line 62
Module implementing EVA extra field and views display

Code

function eva_get_views($type = NULL, $reset = FALSE) {

  // Build and cache the data, both in the DB and statically.
  $views = Views::getApplicableViews('uses_hook_entity_view');
  $used_views = array();
  foreach ($views as $data) {
    list($view_name, $display_id) = $data;
    $view = Views::getView($view_name);

    // Initialize handlers, to determine if the view uses exposed filters.
    $view
      ->setDisplay($display_id);
    $view
      ->initHandlers();
    $display = $view->display_handler;
    $view_entity = $display
      ->getOption('entity_type');
    $used_views[$view_entity][] = array(
      'name' => $view_name,
      'id' => $view->storage
        ->get('id'),
      'title' => 'EVA: ' . $view->storage
        ->get('label') . ' - ' . $view->storage
        ->getDisplay($display_id)['display_title'],
      'display' => $display_id,
      'bundles' => $display
        ->getOption('bundles'),
      'uses exposed' => $display
        ->usesExposed(),
    );
    $view
      ->destroy();
  }
  if (!is_null($type)) {
    return isset($used_views[$type]) ? $used_views[$type] : array();
  }
  return $used_views;
}