diff --git a/core/modules/field_ui/field_ui.admin.inc b/core/modules/field_ui/field_ui.admin.inc index 4f429cc..624f124 100644 --- a/core/modules/field_ui/field_ui.admin.inc +++ b/core/modules/field_ui/field_ui.admin.inc @@ -6,58 +6,6 @@ */ /** - * Page callback: Lists all defined fields for quick reference. - * - * @see field_ui_menu() - */ -function field_ui_fields_list() { - $instances = field_info_instances(); - $field_types = field_info_field_types(); - $bundles = entity_get_bundles(); - $entity_manager = Drupal::entityManager(); - - $modules = system_rebuild_module_data(); - - $header = array( - t('Field name'), - array('data' => t('Field type'), 'class' => array(RESPONSIVE_PRIORITY_MEDIUM)), - 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']; - $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 = $entity_manager->getAdminPath($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 = theme('table', array('header' => $header, 'rows' => $rows)); - } - return $output; -} - -/** * Returns HTML for Field UI overview tables. * * @param $variables diff --git a/core/modules/field_ui/field_ui.module b/core/modules/field_ui/field_ui.module index d115b7f..8b17017 100644 --- a/core/modules/field_ui/field_ui.module +++ b/core/modules/field_ui/field_ui.module @@ -56,8 +56,7 @@ function field_ui_menu() { $items['admin/reports/fields'] = array( 'title' => 'Field list', 'description' => 'Overview of fields on all entity types.', - 'page callback' => 'field_ui_fields_list', - 'access arguments' => array('administer content types'), + 'route_name' => 'field_list', 'type' => MENU_NORMAL_ITEM, 'file' => 'field_ui.admin.inc', ); diff --git a/core/modules/field_ui/field_ui.routing.yml b/core/modules/field_ui/field_ui.routing.yml new file mode 100644 index 0000000..e432c0e --- /dev/null +++ b/core/modules/field_ui/field_ui.routing.yml @@ -0,0 +1,6 @@ +field_list: + pattern: 'admin/reports/fields' + defaults: + _content: '\Drupal\field_ui\Controller\FieldUIController::fieldsList' + requirements: + _permission: 'administer content types' diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Controller/FieldUIController.php b/core/modules/field_ui/lib/Drupal/field_ui/Controller/FieldUIController.php new file mode 100644 index 0000000..c87ee58 --- /dev/null +++ b/core/modules/field_ui/lib/Drupal/field_ui/Controller/FieldUIController.php @@ -0,0 +1,106 @@ +entityManager = $entityManager; + $this->fieldInfo = $fieldInfo; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('plugin.manager.entity'), + $container->get('field.info') + ); + } + + /** + * Returns an administrative overview of all fields for quick overview. + * + * @return string + * A HTML-formatted string with the administrative page content. + */ + public function fieldsList() { + $fields = $this->fieldInfo->getFieldMap(); + $field_types = field_info_field_types(); + $bundles = entity_get_bundles(); + $entity_manager = $this->entityManager; + $modules = system_rebuild_module_data(); + + $header = array( + t('Field name'), + array('data' => t('Field type'), 'class' => array(RESPONSIVE_PRIORITY_MEDIUM)), + t('Used in'), + ); + $rows = array(); + foreach($fields as $field_name => $field_info) { + $field = field_info_field($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']; + $rows[$field_name]['data'][1] = $field_types[$field['type']]['label'] . ' ' . t('(module: !module)', array('!module' => $modules[$module_name]->info['name'])); + + // Add all instances for this field. + foreach($field_info['bundles'] as $entity_type => $field_bundles) { + foreach($field_bundles as $bundle) { + $admin_path = $entity_manager->getAdminPath($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 = theme('table', array('header' => $header, 'rows' => $rows)); + } + return $output; + } +} diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php index c0f5471..4603155 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php @@ -72,6 +72,7 @@ function testCRUDFields() { $this->updateField(); $this->addExistingField(); $this->cardinalitySettings(); + $this->fieldListAdminPage(); } /** @@ -566,4 +567,13 @@ function testHelpDescriptions() { $this->assertRaw('Test with an upload field.'); $this->assertRaw('Test with a non upload field.'); } + + /** + * Tests that the field list administration page operates correctly. + */ + function fieldListAdminPage() { + $this->drupalGet('admin/reports/fields'); + $this->assertText($this->field_name, 'Field name is displayed in field list.'); + $this->assertTrue($this->assertLinkByHref('admin/structure/types/manage/' . $this->type . '/fields'), 'Link to content type using field is displayed in field list.'); + } }