Skip to content
Snippets Groups Projects
Commit 61067b35 authored by Owen Bush's avatar Owen Bush Committed by Andrii Podanenko
Browse files

Resolve issue with creating translations and displaying the event instances

parent 6bdc2517
No related branches found
No related tags found
1 merge request!69Issue #3318666: Event instances are not created with the correct language
......@@ -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);
}
}
}
......
......@@ -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();
}
}
......@@ -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()));
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment