diff --git a/core/modules/field_ui/field_ui.module b/core/modules/field_ui/field_ui.module index 3313ef7..8d52e56 100644 --- a/core/modules/field_ui/field_ui.module +++ b/core/modules/field_ui/field_ui.module @@ -58,7 +58,6 @@ function field_ui_menu() { 'description' => 'Overview of fields on all entity types.', 'route_name' => 'field_list', 'type' => MENU_NORMAL_ITEM, - 'file' => 'field_ui.admin.inc', ); $items['admin/reports/fields/list'] = array( 'title' => 'Entities', @@ -247,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 index e432c0e..946d60e 100644 --- a/core/modules/field_ui/field_ui.routing.yml +++ b/core/modules/field_ui/field_ui.routing.yml @@ -1,6 +1,6 @@ field_list: pattern: 'admin/reports/fields' defaults: - _content: '\Drupal\field_ui\Controller\FieldUIController::fieldsList' + _entity_list: 'field_entity' 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 deleted file mode 100644 index c87ee58..0000000 --- a/core/modules/field_ui/lib/Drupal/field_ui/Controller/FieldUIController.php +++ /dev/null @@ -1,106 +0,0 @@ -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/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; + } + +}