Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d8 / hook / config_translation_info.twig
diff --git a/vendor/chi-teck/drupal-code-generator/templates/d8/hook/config_translation_info.twig b/vendor/chi-teck/drupal-code-generator/templates/d8/hook/config_translation_info.twig
new file mode 100644 (file)
index 0000000..73af8db
--- /dev/null
@@ -0,0 +1,34 @@
+/**
+ * Implements hook_config_translation_info().
+ */
+function {{ machine_name }}_config_translation_info(&$info) {
+  $entity_manager = \Drupal::entityManager();
+  $route_provider = \Drupal::service('router.route_provider');
+
+  // If field UI is not enabled, the base routes of the type
+  // "entity.field_config.{$entity_type}_field_edit_form" are not defined.
+  if (\Drupal::moduleHandler()->moduleExists('field_ui')) {
+    // Add fields entity mappers to all fieldable entity types defined.
+    foreach ($entity_manager->getDefinitions() as $entity_type_id => $entity_type) {
+      $base_route = NULL;
+      try {
+        $base_route = $route_provider->getRouteByName('entity.field_config.' . $entity_type_id . '_field_edit_form');
+      }
+      catch (RouteNotFoundException $e) {
+        // Ignore non-existent routes.
+      }
+
+      // Make sure entity type has field UI enabled and has a base route.
+      if ($entity_type->get('field_ui_base_route') && !empty($base_route)) {
+        $info[$entity_type_id . '_fields'] = [
+          'base_route_name' => 'entity.field_config.' . $entity_type_id . '_field_edit_form',
+          'entity_type' => 'field_config',
+          'title' => t('Title'),
+          'class' => '\Drupal\config_translation\ConfigFieldMapper',
+          'base_entity_type' => $entity_type_id,
+          'weight' => 10,
+        ];
+      }
+    }
+  }
+}