|
8 | 8 | use Drupal\Core\Entity\EntityFieldManagerInterface; |
9 | 9 | use Drupal\Core\Entity\EntityTypeBundleInfoInterface; |
10 | 10 | use Drupal\Core\Entity\EntityTypeManagerInterface; |
| 11 | +use Drupal\Core\Field\BaseFieldDefinition; |
11 | 12 | use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface; |
12 | 13 | use Drupal\graphql\Utility\StringHelper; |
13 | 14 | use Drupal\graphql_content\ContentEntitySchemaConfig; |
@@ -62,6 +63,8 @@ class DisplayedFieldDeriver extends DeriverBase implements ContainerDeriverInter |
62 | 63 | * Bundle info provider. |
63 | 64 | * @param \Drupal\Core\Entity\EntityFieldManagerInterface $entityFieldManager |
64 | 65 | * Entity field manager instance. |
| 66 | + * @param \Drupal\graphql_content\ContentEntitySchemaConfig $schemaConfig |
| 67 | + * The schema config service. |
65 | 68 | */ |
66 | 69 | public function __construct( |
67 | 70 | EntityTypeManagerInterface $entityTypeManager, |
@@ -125,25 +128,31 @@ public function getDerivativeDefinitions($basePluginDefinition) { |
125 | 128 | continue; |
126 | 129 | } |
127 | 130 |
|
128 | | - $storages = $this->entityFieldManager->getFieldStorageDefinitions($typeId); |
129 | | - |
| 131 | + $storageDefinitions = $this->entityFieldManager->getFieldStorageDefinitions($typeId); |
130 | 132 | foreach (array_keys($bundles[$typeId]) as $bundle) { |
131 | 133 | if ($viewMode = $this->schemaConfig->getExposedViewMode($typeId, $bundle)) { |
132 | 134 | if ($display = $this->getDisplay($typeId, $bundle, $viewMode)) { |
133 | 135 | foreach ($display->getComponents() as $field => $component) { |
134 | | - if (isset($component['type']) && $component['type'] == 'graphql_raw_value') { |
| 136 | + if (isset($component['type']) && $component['type'] === 'graphql_raw_value') { |
135 | 137 | // Raw values formatter is obsolete. |
136 | 138 | continue; |
137 | 139 | } |
138 | 140 |
|
| 141 | + $storageDefinition = isset($storageDefinitions[$field]) ? $storageDefinitions[$field] : NULL; |
| 142 | + if (isset($storageDefinition) && $storageDefinition instanceof BaseFieldDefinition) { |
| 143 | + // Skip base fields. We generate them globally across all |
| 144 | + // bundles. |
| 145 | + continue; |
| 146 | + } |
| 147 | + |
139 | 148 | $this->derivatives[$typeId . '-' . $bundle . '-' . $field] = [ |
140 | 149 | 'name' => StringHelper::propCase($field), |
141 | 150 | 'types' => [StringHelper::camelCase([$typeId, $bundle])], |
142 | 151 | 'entity_type' => $typeId, |
143 | 152 | 'bundle' => $bundle, |
144 | 153 | 'field' => $field, |
145 | | - 'virtual' => !array_key_exists($field, $storages), |
146 | | - 'multi' => array_key_exists($field, $storages) ? $storages[$field]->getCardinality() != 1 : FALSE, |
| 154 | + 'virtual' => !isset($storageDefinition), |
| 155 | + 'multi' => isset($storageDefinition) ? $storageDefinition->getCardinality() != 1 : FALSE, |
147 | 156 | 'cache_tags' => $display->getCacheTags(), |
148 | 157 | 'cache_contexts' => $display->getCacheContexts(), |
149 | 158 | 'cache_max_age' => $display->getCacheMaxAge(), |
|
0 commit comments