3 namespace Drupal\field_ui;
5 use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
6 use Drupal\Core\Entity\EntityInterface;
7 use Drupal\Core\Entity\EntityManagerInterface;
8 use Drupal\Core\Entity\EntityTypeInterface;
9 use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
10 use Drupal\Core\Field\FieldTypePluginManagerInterface;
11 use Symfony\Component\DependencyInjection\ContainerInterface;
14 * Defines a class to build a listing of fields.
16 * @see \Drupal\field\Entity\Field
17 * @see field_ui_entity_info()
19 class FieldStorageConfigListBuilder extends ConfigEntityListBuilder {
22 * An array of information about field types.
26 protected $fieldTypes;
31 * @var \Drupal\Core\Entity\EntityManagerInterface
33 protected $entityManager;
36 * An array of entity bundle information.
43 * The field type manager.
45 * @var \Drupal\Core\Field\FieldTypePluginManagerInterface
47 protected $fieldTypeManager;
50 * Constructs a new FieldStorageConfigListBuilder object.
52 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
53 * The entity type definition.
54 * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
56 * @param \Drupal\Core\Field\FieldTypePluginManagerInterface $field_type_manager
57 * The 'field type' plugin manager.
59 public function __construct(EntityTypeInterface $entity_type, EntityManagerInterface $entity_manager, FieldTypePluginManagerInterface $field_type_manager, EntityTypeBundleInfoInterface $bundle_info_service) {
60 parent::__construct($entity_type, $entity_manager->getStorage($entity_type->id()));
62 $this->entityManager = $entity_manager;
63 $this->bundles = $bundle_info_service->getAllBundleInfo();
64 $this->fieldTypeManager = $field_type_manager;
65 $this->fieldTypes = $this->fieldTypeManager->getDefinitions();
71 public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
74 $container->get('entity.manager'),
75 $container->get('plugin.manager.field.field_type'),
76 $container->get('entity_type.bundle.info')
83 public function buildHeader() {
84 $header['id'] = $this->t('Field name');
85 $header['entity_type'] = $this->t('Entity type');
87 'data' => $this->t('Field type'),
88 'class' => [RESPONSIVE_PRIORITY_MEDIUM],
90 $header['usage'] = $this->t('Used in');
97 public function buildRow(EntityInterface $field_storage) {
98 if ($field_storage->isLocked()) {
99 $row['class'] = ['menu-disabled'];
100 $row['data']['id'] = $this->t('@field_name (Locked)', ['@field_name' => $field_storage->getName()]);
103 $row['data']['id'] = $field_storage->getName();
106 $entity_type_id = $field_storage->getTargetEntityTypeId();
107 // Adding the entity type.
108 $row['data']['entity_type'] = $entity_type_id;
110 $field_type = $this->fieldTypes[$field_storage->getType()];
111 $row['data']['type'] = $this->t('@type (module: @module)', ['@type' => $field_type['label'], '@module' => $field_type['provider']]);
114 foreach ($field_storage->getBundles() as $bundle) {
115 if ($route_info = FieldUI::getOverviewRouteInfo($entity_type_id, $bundle)) {
116 $usage[] = \Drupal::l($this->bundles[$entity_type_id][$bundle]['label'], $route_info);
119 $usage[] = $this->bundles[$entity_type_id][$bundle]['label'];
122 $row['data']['usage']['data'] = [
123 '#theme' => 'item_list',
125 '#context' => ['list_style' => 'comma-list'],