From 34f17a134376c1a059933f4f6d6925e1639ddb46 Mon Sep 17 00:00:00 2001 From: pfleu <fleutotp@gmail.com> Date: Thu, 10 Aug 2023 16:44:51 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20on=20v=C3=A9rifie=20qu'on=20a=20pas=20d?= =?UTF-8?q?=C3=A9j=C3=A0=20un=20headword=20avant=20de=20le=20cr=C3=A9er=20?= =?UTF-8?q?quand=20on=20cr=C3=A9e=20une=20entr=C3=A9e=20depuis=20la=20sear?= =?UTF-8?q?chbar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Controller/HeadwordController.php | 20 ++++++++++++++++---- templates/entry/_entryAttributes.html.twig | 2 +- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Controller/HeadwordController.php b/src/Controller/HeadwordController.php index 2b7cc97..15eeecc 100644 --- a/src/Controller/HeadwordController.php +++ b/src/Controller/HeadwordController.php @@ -62,7 +62,13 @@ class HeadwordController extends AppBaseController return new JsonResponse($this->generateUrl('app_entry_show', ['id' => $entries[0]->getId()]), 211); } elseif ($wiktionaryManager->search($search, $this->getLanguage())) { - $headword = $this->newHeadword($search, $this->getLanguage()); + $headword = $this->em->getRepository(Headword::class)->findOneBy([ + 'value' => $search, + 'language' => $this->getLanguage(), + ]); + if (!$headword) { + $headword = $this->newHeadword($search, $this->getLanguage()); + } $entry = $this->getOrCreateEntryInZeroLexicon($headword); $this->em->flush(); $this->addFlash('success', "« " . $search . " » a été ajouté à Balex depuis le wiktionnaire"); @@ -70,8 +76,8 @@ class HeadwordController extends AppBaseController return new JsonResponse($this->generateUrl('app_entry_show', ['id' => $entry->getId()]), 211); } else { - return $this->render("headword/confirmAddNewWord.html.twig", ['word' => $search]); - } + return $this->render("headword/confirmAddNewWord.html.twig", ['word' => $search]); + } } /** @@ -80,7 +86,13 @@ class HeadwordController extends AppBaseController public function confirmNewWordCreation(Request $request): Response { $word = $request->get('word'); - $headword = $this->newHeadword($word, $this->getLanguage()); + $headword = $this->em->getRepository(Headword::class)->findOneBy([ + 'value' => $word, + 'language' => $this->getLanguage(), + ]); + if (!$headword) { + $headword = $this->newHeadword($word, $this->getLanguage()); + } $this->createEntryInNewWordsLexicon($headword); $this->em->flush(); diff --git a/templates/entry/_entryAttributes.html.twig b/templates/entry/_entryAttributes.html.twig index 52ebc58..313d013 100644 --- a/templates/entry/_entryAttributes.html.twig +++ b/templates/entry/_entryAttributes.html.twig @@ -40,7 +40,7 @@ {% set pronunciationKey = '[Items][0][Sense][Pronunciations]['~key~']' %} <li id="{{ pronunciation.id }}"> - <div class="links-container"> + <div class="links-container pb-1"> {% if pronunciation.accent is defined %}{{ pronunciation.accent }} :{% endif %} {{ pronunciation.api }} {% for sound in pronunciation.sounds|default([]) %} -- GitLab