function views_ui_field_list in Views (for Drupal 7) 8.3
Same name and namespace in other branches
- 7.3 includes/admin.inc \views_ui_field_list()
List all instances of fields on any views.
Therefore it builds up a table of each field which is used in any view.
See also
field_ui_fields_list()
1 string reference to 'views_ui_field_list'
- views_ui_menu in views_ui/
views_ui.module - Implements hook_menu().
File
- views_ui/
admin.inc, line 2702 - Provides the Views' administrative interface.
Code
function views_ui_field_list() {
$views = views_get_all_views();
// Fetch all fieldapi fields which are used in views
// Therefore search in all views, displays and handler-types.
$fields = array();
$handler_types = ViewUI::viewsHandlerTypes();
foreach ($views as $view) {
$view = $view
->getExecutable();
$view
->initDisplay();
foreach ($view->displayHandlers as $display_id => $display) {
if ($view
->setDisplay($display_id)) {
foreach ($handler_types as $type => $info) {
foreach ($view
->getItems($type, $display_id) as $item) {
$data = views_fetch_data($item['table']);
if (isset($data[$item['field']]) && isset($data[$item['field']][$type]) && ($data = $data[$item['field']][$type])) {
// The final check that we have a fieldapi field now.
if (isset($data['field_name'])) {
$fields[$data['field_name']][$view->storage->name] = $view->storage->name;
}
}
}
}
}
}
}
$header = array(
t('Field name'),
t('Used in'),
);
$rows = array();
foreach ($fields as $field_name => $views) {
$rows[$field_name]['data'][0] = check_plain($field_name);
foreach ($views as $view) {
$rows[$field_name]['data'][1][] = l($view, "admin/structure/views/view/{$view}");
}
$rows[$field_name]['data'][1] = implode(', ', $rows[$field_name]['data'][1]);
}
// Sort rows by field name.
ksort($rows);
$output = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => t('No fields have been used in views yet.'),
);
return $output;
}