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 fefd9a1..8d52e56 100644 --- a/core/modules/field_ui/field_ui.module +++ b/core/modules/field_ui/field_ui.module @@ -56,10 +56,8 @@ 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', ); $items['admin/reports/fields/list'] = array( 'title' => 'Entities', @@ -248,6 +246,7 @@ function field_ui_element_info() { */ function field_ui_entity_info(&$entity_info) { $entity_info['field_instance']['controllers']['form']['delete'] = 'Drupal\field_ui\Form\FieldDeleteForm'; + $entity_info['field_entity']['controllers']['list'] = 'Drupal\field_ui\FieldListController'; } /** 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..946d60e --- /dev/null +++ b/core/modules/field_ui/field_ui.routing.yml @@ -0,0 +1,6 @@ +field_list: + pattern: 'admin/reports/fields' + defaults: + _entity_list: 'field_entity' + requirements: + _permission: 'administer content types' diff --git a/core/modules/field_ui/lib/Drupal/field_ui/FieldListController.php b/core/modules/field_ui/lib/Drupal/field_ui/FieldListController.php new file mode 100644 index 0000000..cd3d640 --- /dev/null +++ b/core/modules/field_ui/lib/Drupal/field_ui/FieldListController.php @@ -0,0 +1,125 @@ +getStorageController($entity_type), $module_handler); + + $this->fieldTypes = field_info_field_types(); + $this->fieldInfo = $field_info->getFieldMap(); + $this->entityManager = $entity_manager; + $this->bundles = entity_get_bundles(); + } + + /** + * {@inheritdoc} + */ + public static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) { + return new static( + $entity_type, + $entity_info, + $container->get('plugin.manager.entity'), + $container->get('module_handler'), + $container->get('field.info') + ); + } + + /** + * {@inheritdoc} + */ + public function buildHeader() { + $row['id'] = t('Field name'); + $row['type'] = array( + 'data' => t('Field type'), + 'class' => array(RESPONSIVE_PRIORITY_MEDIUM), + ); + $row['usage'] = t('Used in'); + return $row; + } + + /** + * {@inheritdoc} + */ + public function buildRow(EntityInterface $entity) { + if ($entity->locked) { + $row['class'] = array('menu-disabled'); + $row['data']['id'] = t('@field_name (Locked)', array('@field_name' => $entity->id())); + } + else { + $row['data']['id'] = $entity->id(); + } + + $field_type = $this->fieldTypes[$entity->getFieldType()]; + $row['data']['type'] = t('@type (module: @module)', array('@type' => $field_type['label'], '@module' => $field_type['module'])); + + $usage = array(); + foreach($this->fieldInfo[$entity->id()]['bundles'] as $entity_type => $field_bundles) { + foreach($field_bundles as $bundle) { + $admin_path = $this->entityManager->getAdminPath($entity_type, $bundle); + $usage[] = $admin_path ? l($this->bundles[$entity_type][$bundle]['label'], $admin_path . '/fields') : $this->bundles[$entity_type][$bundle]['label']; + } + } + $row['data']['usage'] = implode(', ', $usage); + return $row; + } + +} 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 471a575..7df6695 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(); } /** @@ -595,4 +596,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.'); + } }