-
Notifications
You must be signed in to change notification settings - Fork 0
/
plug_field.admin.inc
61 lines (54 loc) · 2.14 KB
/
plug_field.admin.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
/**
* @file
* Administrative interface for Plug Field module.
*/
use \Drupal\plug_field\PlugFieldTypeManager;
/**
* Menu callback; lists all defined fields for quick reference.
*/
function plug_field_field_ui_fields_list() {
$instances = field_info_instances();
$field_types = field_info_field_types();
$bundles = field_info_bundles();
$definitions = PlugFieldTypeManager::get()->getDefinitions();
$modules = system_rebuild_module_data();
$header = array(t('Field name'), t('Field type'), t('Used in'));
$rows = array();
foreach ($instances as $entity_type => $type_bundles) {
foreach ($type_bundles as $bundle => $bundle_instances) {
foreach ($bundle_instances as $field_name => $instance) {
$field = field_info_field($field_name);
// Initialize the row if we encounter the field for the first time.
if (!isset($rows[$field_name])) {
$rows[$field_name]['class'] = $field['locked'] ? array('menu-disabled') : array('');
$rows[$field_name]['data'][0] = $field['locked'] ? t('@field_name (Locked)', array('@field_name' => $field_name)) : $field_name;
$module_name = $field_types[$field['type']]['module'];
if ($module_name == 'plug_field') {
$module_name = $definitions[$field['type']]['provider'];
}
$rows[$field_name]['data'][1] = $field_types[$field['type']]['label'] . ' ' . t('(module: !module)', array('!module' => $modules[$module_name]->info['name']));
}
// Add the current instance.
$admin_path = _field_ui_bundle_admin_path($entity_type, $bundle);
$rows[$field_name]['data'][2][] = $admin_path ? l($bundles[$entity_type][$bundle]['label'], $admin_path . '/fields') : $bundles[$entity_type][$bundle]['label'];
}
}
}
foreach ($rows as $field_name => $cell) {
$rows[$field_name]['data'][2] = implode(', ', $cell['data'][2]);
}
if (empty($rows)) {
$output = t('No fields have been defined yet.');
}
else {
// Sort rows by field name.
ksort($rows);
$output = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
);
}
return $output;
}