|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace WebVision\WvDeepltranslate\Hooks\Glossary; |
| 6 | + |
| 7 | +use TYPO3\CMS\Core\DataHandling\DataHandler; |
| 8 | +use TYPO3\CMS\Core\Messaging\FlashMessage; |
| 9 | +use TYPO3\CMS\Core\Messaging\FlashMessageService; |
| 10 | +use TYPO3\CMS\Core\Utility\GeneralUtility; |
| 11 | +use TYPO3\CMS\Extbase\Utility\LocalizationUtility; |
| 12 | +use WebVision\WvDeepltranslate\Domain\Repository\GlossaryEntryRepository; |
| 13 | +use WebVision\WvDeepltranslate\Domain\Repository\GlossaryRepository; |
| 14 | + |
| 15 | +class UpdatedGlossaryEntryTermHook |
| 16 | +{ |
| 17 | + private GlossaryRepository $glossaryRepository; |
| 18 | + |
| 19 | + private GlossaryEntryRepository $glossaryEntryRepository; |
| 20 | + |
| 21 | + public function __construct( |
| 22 | + ?GlossaryRepository $glossaryRepository = null, |
| 23 | + ?GlossaryEntryRepository $glossaryEntryRepository = null |
| 24 | + ) { |
| 25 | + $this->glossaryRepository = $glossaryRepository ?? GeneralUtility::makeInstance(GlossaryRepository::class); |
| 26 | + $this->glossaryEntryRepository = $glossaryEntryRepository ?? GeneralUtility::makeInstance(GlossaryEntryRepository::class); |
| 27 | + } |
| 28 | + |
| 29 | + /** |
| 30 | + * @param int|string $id |
| 31 | + * @param array{glossary: int} $fieldArray |
| 32 | + */ |
| 33 | + public function processDatamap_afterDatabaseOperations( |
| 34 | + string $status, |
| 35 | + string $table, |
| 36 | + $id, |
| 37 | + array $fieldArray, |
| 38 | + DataHandler $dataHandler |
| 39 | + ): void { |
| 40 | + if ($status !== 'update') { |
| 41 | + return; |
| 42 | + } |
| 43 | + |
| 44 | + if ($table !== 'tx_wvdeepltranslate_glossaryentry') { |
| 45 | + return; |
| 46 | + } |
| 47 | + |
| 48 | + $glossary = $this->glossaryEntryRepository->findEntryByUid($id); |
| 49 | + |
| 50 | + if (empty($glossary)) { |
| 51 | + return; |
| 52 | + } |
| 53 | + |
| 54 | + $this->glossaryRepository->setGlossaryNotSyncOnPage($glossary['pid']); |
| 55 | + |
| 56 | + $flashMessage = new FlashMessage( |
| 57 | + LocalizationUtility::translate( |
| 58 | + 'glossary.not-sync.message', |
| 59 | + 'wv_deepltranslate' |
| 60 | + ), |
| 61 | + LocalizationUtility::translate( |
| 62 | + 'glossary.not-sync.title', |
| 63 | + 'wv_deepltranslate' |
| 64 | + ), |
| 65 | + FlashMessage::INFO, |
| 66 | + true |
| 67 | + ); |
| 68 | + |
| 69 | + GeneralUtility::makeInstance(FlashMessageService::class) |
| 70 | + ->getMessageQueueByIdentifier() |
| 71 | + ->enqueue($flashMessage); |
| 72 | + } |
| 73 | +} |
0 commit comments