diff --git a/src/EventCreationService.php b/src/EventCreationService.php index b504f04885f833cfb59b98055c9f710fee3f8ecf..edb51d9a085077608aac5fcd0d8f4d63b4ce83dc 100644 --- a/src/EventCreationService.php +++ b/src/EventCreationService.php @@ -533,7 +533,12 @@ class EventCreationService { $entity = $storage->create($data); } else { + // Grab the untranslated event series. $original = $event->getUntranslated(); + // Find the corresponding default language event instance that matches + // the date and time of the version we wish to translate, so that we are + // mapping the translations from default language to translated language + // appropriately. $entity_ids = $storage->getQuery() ->condition('date__value', $data['date']['value']) ->condition('date__end_value', $data['date']['end_value']) @@ -544,8 +549,12 @@ class EventCreationService { ->execute(); if (!empty($entity_ids)) { + // Load the default language version of the event instance. $entity = $storage->load(reset($entity_ids)); - $entity->addTranslation($event->language()->getId(), $data); + // Only add a translation if we do not already have one. + if (!$entity->hasTranslation($event->language()->getId())) { + $entity->addTranslation($event->language()->getId(), $data); + } } } diff --git a/src/EventUserTrait.php b/src/EventUserTrait.php index e80b1122ac5cfb45b7423ebc1484770fc2bf2c45..79694531f0347df2656fb347f13d2fb137d735eb 100644 --- a/src/EventUserTrait.php +++ b/src/EventUserTrait.php @@ -80,4 +80,15 @@ trait EventUserTrait { public static function getDefaultEntityOwner() { return \Drupal::currentUser()->id(); } + + /** + * Backwards compatibility for getCurrentUserId(). + * + * @return mixed + * A default value for the uid field. + */ + public static function getCurrentUserId() { + return static::getDefaultEntityOwner(); + } + } diff --git a/src/Plugin/ComputedField/EventInstances.php b/src/Plugin/ComputedField/EventInstances.php index 294679ac3077e3facc008d58168cac585182d230..769412bc3770c45848d654f2c88bb680c4a026eb 100644 --- a/src/Plugin/ComputedField/EventInstances.php +++ b/src/Plugin/ComputedField/EventInstances.php @@ -20,7 +20,6 @@ class EventInstances extends EntityReferenceFieldItemList { if (!empty($entity->id())) { $instances = \Drupal::entityTypeManager()->getStorage('eventinstance')->loadByProperties([ 'eventseries_id' => $entity->id(), - 'langcode' => $this->getLangcode(), ]); // Sort by instance start date and reindex by field item delta, as @@ -30,7 +29,7 @@ class EventInstances extends EntityReferenceFieldItemList { }); foreach ($instances as $key => $instance) { - $this->list[$key] = $this->createItem($key, $instance); + $this->list[$key] = $this->createItem($key, $instance->getTranslation($this->getLangcode())); } } }