From 6323f98c49c5e3970eacf15d05fbca9639164380 Mon Sep 17 00:00:00 2001 From: webchick <webchick@24967.no-reply.drupal.org> Date: Tue, 29 Jan 2013 19:42:19 -0800 Subject: [PATCH] Issue #1900962 by damiankloip, tim.plunkett, dawehner: Use Config Entity query for views_get_applicable_views(). --- core/modules/views/views.module | 36 +++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/core/modules/views/views.module b/core/modules/views/views.module index 389d254c973f..213f12acec1a 100644 --- a/core/modules/views/views.module +++ b/core/modules/views/views.module @@ -1101,7 +1101,11 @@ function views_get_enabled_display_extenders() { * Return a list of all views and display IDs that have a particular * setting in their display's plugin settings. * - * @return + * @param string $type + * A flag from the display plugin definitions (e.g, 'uses_hook_menu'). + * + * @return array + * A list of arrays containing the $view and $display_id. * @code * array( * array($view, $display_id), @@ -1110,32 +1114,34 @@ function views_get_enabled_display_extenders() { * @endcode */ function views_get_applicable_views($type) { - // @todo: Use a smarter flagging system so that we don't have to - // load every view for this. - $result = array(); - $views = views_get_all_views(); + $container = drupal_container(); - foreach ($views as $view) { - // Skip disabled views. - if (!$view->isEnabled()) { - continue; + // Get all display plugins which provides the type. + $display_plugins = $container->get('plugin.manager.views.display')->getDefinitions(); + $ids = array(); + foreach ($display_plugins as $id => $definition) { + if (!empty($definition[$type])) { + $ids[$id] = $id; } + } - $display = $view->get('display'); - if (empty($display)) { - // Skip this view as it is broken. - continue; - } + $entity_ids = $container->get('entity.query')->get('view') + ->condition('disabled', FALSE) + ->condition("display.*.display_plugin", $ids, 'IN') + ->execute(); + $result = array(); + foreach ($container->get('plugin.manager.entity')->getStorageController('view')->load($entity_ids) as $view) { // Check each display to see if it meets the criteria and is enabled. $executable = $view->get('executable'); - $executable->setDisplay(); + $executable->initDisplay(); foreach ($executable->displayHandlers as $id => $handler) { if (!empty($handler->definition[$type]) && $handler->isEnabled()) { $result[] = array($executable, $id); } } } + return $result; } -- GitLab