public function ViewsUIController::reportFields in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/views_ui/src/Controller/ViewsUIController.php \Drupal\views_ui\Controller\ViewsUIController::reportFields()
Lists all instances of fields on any views.
Return value
array The Views fields report page.
1 string reference to 'ViewsUIController::reportFields'
- views_ui.routing.yml in core/
modules/ views_ui/ views_ui.routing.yml - core/modules/views_ui/views_ui.routing.yml
File
- core/
modules/ views_ui/ src/ Controller/ ViewsUIController.php, line 60 - Contains \Drupal\views_ui\Controller\ViewsUIController.
Class
- ViewsUIController
- Returns responses for Views UI routes.
Namespace
Drupal\views_ui\ControllerCode
public function reportFields() {
$views = $this
->entityManager()
->getStorage('view')
->loadMultiple();
// Fetch all fieldapi fields which are used in views
// Therefore search in all views, displays and handler-types.
$fields = array();
$handler_types = ViewExecutable::getHandlerTypes();
foreach ($views as $view) {
$executable = $view
->getExecutable();
$executable
->initDisplay();
foreach ($executable->displayHandlers as $display_id => $display) {
if ($executable
->setDisplay($display_id)) {
foreach ($handler_types as $type => $info) {
foreach ($executable
->getHandlers($type, $display_id) as $item) {
$table_data = $this->viewsData
->get($item['table']);
if (isset($table_data[$item['field']]) && isset($table_data[$item['field']][$type]) && ($field_data = $table_data[$item['field']][$type])) {
// The final check that we have a fieldapi field now.
if (isset($field_data['field_name'])) {
$fields[$field_data['field_name']][$view
->id()] = $view
->id();
}
}
}
}
}
}
}
$header = array(
t('Field name'),
t('Used in'),
);
$rows = array();
foreach ($fields as $field_name => $views) {
$rows[$field_name]['data'][0]['data']['#plain_text'] = $field_name;
foreach ($views as $view) {
$rows[$field_name]['data'][1][] = $this
->l($view, new Url('entity.view.edit_form', array(
'view' => $view,
)));
}
$item_list = [
'#theme' => 'item_list',
'#items' => $rows[$field_name]['data'][1],
'#context' => [
'list_style' => 'comma-list',
],
];
$rows[$field_name]['data'][1] = [
'data' => $item_list,
];
}
// Sort rows by field name.
ksort($rows);
$output = array(
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => t('No fields have been used in views yet.'),
);
return $output;
}