Skip to content

Commit

Permalink
Fix in case of update after adding new language
Browse files Browse the repository at this point in the history
  • Loading branch information
Carmine Di Gruttola committed Aug 28, 2023
1 parent 48d31aa commit eca51ca
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/Form/DataHandler/ImageSliderFormDataHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,12 @@ public function update($id, array $data): int
$langId = (int) $language['id_lang'];
$imageSliderLang = $imageSlide->getImageSliderLangByLangId($langId);

$newImageSliderLang = false;
if (null === $imageSliderLang) {
continue;
$imageSliderLang = new ImageSliderLang();
$lang = $this->langRepository->findOneById($langId);
$imageSliderLang->setLang($lang);
$newImageSliderLang = true;
}

$imageSliderLang
Expand All @@ -137,14 +141,22 @@ public function update($id, array $data): int
->setDescription($data['description'][$langId] ?? '');

if (!empty($data['image'][$langId])) {
$this->eraseFile($imageSliderLang->getImage());
if (!$newImageSliderLang) {
$this->eraseFile($imageSliderLang->getImage());
}
$imageSliderLang->setImage($this->uploadFile($data['image'][$langId]));
}

if (!empty($data['image_mobile'][$langId])) {
$this->eraseFile($imageSliderLang->getImageMobile());
if (!$newImageSliderLang) {
$this->eraseFile($imageSliderLang->getImageMobile());
}
$imageSliderLang->setImageMobile($this->uploadFile($data['image_mobile'][$langId]));
}

if ($newImageSliderLang) {
$imageSlide->addImageSliderLang($imageSliderLang);
}
}

$this->entityManager->flush();
Expand Down

0 comments on commit eca51ca

Please sign in to comment.