Active
Project:
Views (for Drupal 7)
Version:
7.x-3.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
5 May 2013 at 08:06 UTC
Updated:
5 May 2013 at 08:06 UTC
I've a strange feeling I've asked for this before.
Anyway, I needed to check which Views used a custom handler class I was about to change, so here's a function that reports on handler usage:
/**
* Lists all handlers and what enabled Views use them.
*/
function views_ui_handler_list() {
views_include('view');
$display_objects = views_object_types();
$handler_info = array();
$table_data = views_fetch_data();
foreach (views_get_enabled_views() as $view) {
foreach ($view->display as $display_id => $display) {
foreach ($display_objects as $display_object => $display_object_type) {
if (!isset($display->display_options[$display_object_type['plural']])) {
continue;
}
$handler_list = $display->display_options[$display_object_type['plural']];
foreach ($handler_list as $handler) {
// Create a unique key, as ids are unique only per table.
$key = $handler['table'] . ':' . $handler['id'];
$handler_info[$key] = array(
'type' => $display_object,
'table' => $handler['table'],
'id' => $handler['id'],
'handler' => $table_data[$handler['table']][$handler['id']][$display_object]['handler'],
);
$handler_info[$key]['views'][] = $view->name;
}
}
}
}
$rows = $handler_info;
foreach ($rows as &$row) {
// Link each view name to the view itself.
$views_links = array();
foreach ($row['views'] as $view) {
$views_links[] = l($view, "admin/structure/views/view/$view");
}
$row['views'] = implode(', ', $views_links);
}
// Sort rows by field name.
ksort($rows);
return array(
'#theme' => 'table',
'#header' => array(t('Type'), t('Table'), t('Id'), t('Class'), t('Used in')),
'#rows' => $rows,
'#empty' => t('There are no enabled views.'),
);
}