public function ViewDisplays::get in EVA: Entity Views Attachment 8.2
Get 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: The entity type we want to retrieve views for. If NULL is specified, views for all entity types will be returned.
Return value
array An array of view name/display name values, or an empty array().
1 call to ViewDisplays::get()
- ViewDisplays::clearDetached in src/
ViewDisplays.php - Remove a removed extra field from entity displays.
File
- src/
ViewDisplays.php, line 83
Class
- ViewDisplays
- EVA utiltity service.
Namespace
Drupal\evaCode
public function get($type = NULL) {
// Collect a list of EVAs and cache it.
$cache = $this->defaultCache
->get($this->cacheId);
$used_views = [];
if ($cache) {
$used_views = $cache->data;
}
if (!$used_views) {
$views = Views::getApplicableViews('uses_hook_entity_view');
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][] = [
'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();
}
$this->defaultCache
->set($this->cacheId, $used_views, CacheBackendInterface::CACHE_PERMANENT);
}
if (!is_null($type)) {
return isset($used_views[$type]) ? $used_views[$type] : [];
}
return $used_views;
}