From 4119b5dc8fac5ad501c6919241a8f87674053a61 Mon Sep 17 00:00:00 2001
From: "tim.plunkett" <tim.plunkett@241634.no-reply.drupal.org>
Date: Mon, 16 Jul 2012 19:30:59 +0200
Subject: [PATCH] Issue #1686798 by tim.plunkett: Added a list of which plugins
 are from which modules and used in which views.

---
 includes/admin.inc | 23 +++++++++++++++++++++
 views.module       | 51 ++++++++++++++++++++++++++++++++++++++++++++++
 views_ui.module    |  7 +++++++
 3 files changed, 81 insertions(+)

diff --git a/includes/admin.inc b/includes/admin.inc
index b6758370161f..0e57120ef3bb 100644
--- a/includes/admin.inc
+++ b/includes/admin.inc
@@ -5411,3 +5411,26 @@ function views_ui_field_list() {
 
   return $output;
 }
+
+/**
+ * Lists all plugins and what enabled Views use them.
+ */
+function views_ui_plugin_list() {
+  $rows = views_plugin_list();
+  foreach ($rows as &$row) {
+    // Link each view name to the view itself.
+    foreach ($row['views'] as $row_name => $view) {
+      $row['views'][$row_name] = l($view, "admin/structure/views/view/$view");
+    }
+    $row['views'] = implode(', ', $row['views']);
+  }
+
+  // Sort rows by field name.
+  ksort($rows);
+  return array(
+    '#theme' => 'table',
+    '#header' => array(t('Type'), t('Name'), t('Provided by'), t('Used in')),
+    '#rows' => $rows,
+    '#empty' => t('There are no enabled views.'),
+  );
+}
diff --git a/views.module b/views.module
index e49d51a9487b..32d5739d111b 100644
--- a/views.module
+++ b/views.module
@@ -269,6 +269,57 @@ function _views_find_module_templates($cache, $path) {
   return $templates;
 }
 
+/**
+ * Returns a list of plugins and metadata about them.
+ *
+ * @return array
+ *   An array keyed by PLUGIN_TYPE:PLUGIN_NAME, like 'display:page' or
+ *   'pager:full', containing an array with the following keys:
+ *   - title: The plugin's title.
+ *   - type: The plugin type.
+ *   - module: The module providing the plugin.
+ *   - views: An array of enabled Views that are currently using this plugin,
+ *     keyed by machine name.
+ */
+function views_plugin_list() {
+  $plugin_data = views_fetch_plugin_data();
+  $plugins = array();
+  foreach (views_get_enabled_views() as $view) {
+    foreach ($view->display as $display_id => $display) {
+      foreach ($plugin_data as $type => $info) {
+        if ($type == 'display' && isset($display->display_plugin)) {
+          $name = $display->display_plugin;
+        }
+        elseif (isset($display->display_options["{$type}_plugin"])) {
+          $name = $display->display_options["{$type}_plugin"];
+        }
+        elseif (isset($display->display_options[$type]['type'])) {
+          $name = $display->display_options[$type]['type'];
+        }
+        else {
+          continue;
+        }
+
+        // Key first by the plugin type, then the name.
+        $key = $type . ':' . $name;
+        // Add info for this plugin.
+        if (!isset($plugins[$key])) {
+          $plugins[$key] = array(
+            'type' => $type,
+            'title' => check_plain($info[$name]['title']),
+            'module' => check_plain($info[$name]['module']),
+            'views' => array(),
+          );
+        }
+
+        // Add this view to the list for this plugin.
+        $plugins[$key]['views'][$view->name] = $view->name;
+      }
+    }
+  }
+  return $plugins;
+}
+
 /**
  * A theme preprocess function to automatically allow view-based node
  * templates if called from a view.
diff --git a/views_ui.module b/views_ui.module
index b3864bd75fcf..160f83937b68 100644
--- a/views_ui.module
+++ b/views_ui.module
@@ -152,6 +152,13 @@ function views_ui_menu() {
     'page callback' => 'views_ui_field_list',
   ) + $base;
 
+  // A page in the Reports section to show usage of plugins in all views.
+  $items['admin/reports/views-plugins'] = array(
+    'title' => 'Views plugins',
+    'description' => 'Overview of plugins used in all views.',
+    'page callback' => 'views_ui_plugin_list',
+  ) + $base;
+
   return $items;
 }
 
-- 
GitLab