Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d8 / hook / entity_field_storage_info.twig
diff --git a/vendor/chi-teck/drupal-code-generator/templates/d8/hook/entity_field_storage_info.twig b/vendor/chi-teck/drupal-code-generator/templates/d8/hook/entity_field_storage_info.twig
new file mode 100644 (file)
index 0000000..1326549
--- /dev/null
@@ -0,0 +1,20 @@
+/**
+ * Implements hook_entity_field_storage_info().
+ */
+function {{ machine_name }}_entity_field_storage_info(\Drupal\Core\Entity\EntityTypeInterface $entity_type) {
+  if (\Drupal::entityManager()->getStorage($entity_type->id()) instanceof DynamicallyFieldableEntityStorageInterface) {
+    // Query by filtering on the ID as this is more efficient than filtering
+    // on the entity_type property directly.
+    $ids = \Drupal::entityQuery('field_storage_config')
+      ->condition('id', $entity_type->id() . '.', 'STARTS_WITH')
+      ->execute();
+    // Fetch all fields and key them by field name.
+    $field_storages = FieldStorageConfig::loadMultiple($ids);
+    $result = [];
+    foreach ($field_storages as $field_storage) {
+      $result[$field_storage->getName()] = $field_storage;
+    }
+
+    return $result;
+  }
+}