From 3c05b4548c947442a38a16c0ae901fd6aa5f1b03 Mon Sep 17 00:00:00 2001 From: Elias Tertsunen Date: Fri, 28 Jan 2022 13:29:42 +0200 Subject: [PATCH] Set default language code on new addresses When adding a new address to an existing library, the submission fails because of the missing language code. This commit remedies that. --- src/Form/LibraryForm.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Form/LibraryForm.php b/src/Form/LibraryForm.php index 5322faf..82f185a 100644 --- a/src/Form/LibraryForm.php +++ b/src/Form/LibraryForm.php @@ -210,6 +210,15 @@ public function form(FormBuilderInterface $builder, array $options) : void FormData::persistTemporaryTranslation($address->getTranslations(), $langcode); } } else { + // Rarely an existing library without an address is found. If + // this is the case then the default language code needs to be + // set from the library otherwise the address insertion will fail. + $address = $data->getAddress(); + + if($address && !$address->getDefaultLangcode()) { + $address->setDefaultLangcode($data->getDefaultLangcode()); + } + $mail_address = $data->getMailAddress(); if($mail_address && !$mail_address->getDefaultLangcode()) {