Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d8 / hook / entity_presave.twig
diff --git a/vendor/chi-teck/drupal-code-generator/templates/d8/hook/entity_presave.twig b/vendor/chi-teck/drupal-code-generator/templates/d8/hook/entity_presave.twig
new file mode 100644 (file)
index 0000000..1708dcb
--- /dev/null
@@ -0,0 +1,9 @@
+/**
+ * Implements hook_entity_presave().
+ */
+function {{ machine_name }}_entity_presave(Drupal\Core\Entity\EntityInterface $entity) {
+  if ($entity instanceof ContentEntityInterface && $entity->isTranslatable()) {
+    $route_match = \Drupal::routeMatch();
+    \Drupal::service('content_translation.synchronizer')->synchronizeFields($entity, $entity->language()->getId(), $route_match->getParameter('source_langcode'));
+  }
+}