Skip to content

Commit

Permalink
[TASK] Move flashMassages out auf services class
Browse files Browse the repository at this point in the history
  • Loading branch information
NarkNiro committed Apr 16, 2024
1 parent 982311d commit 4e5be02
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
16 changes: 16 additions & 0 deletions Classes/Hooks/AbstractTranslateHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

namespace WebVision\WvDeepltranslate\Hooks;

use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\DataHandling\DataHandler;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Messaging\FlashMessageService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use WebVision\WvDeepltranslate\Domain\Repository\PageRepository;
use WebVision\WvDeepltranslate\Exception\ApiKeyNotSetException;
use WebVision\WvDeepltranslate\Service\DeeplService;
Expand Down Expand Up @@ -58,6 +62,18 @@ public function translateContent(
}

if ($response === null) {
if (!Environment::isCli() || !Environment::getContext()->isTesting()) {
$flashMessage = GeneralUtility::makeInstance(
FlashMessage::class,
'Translation not successful', // ToDo use locallang label
'',
-1
);
GeneralUtility::makeInstance(FlashMessageService::class)
->getMessageQueueByIdentifier()
->addMessage($flashMessage);
}

return $content;
}

Expand Down
17 changes: 3 additions & 14 deletions Classes/Service/DeeplService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Exception\SiteNotFoundException;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Messaging\FlashMessageService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use WebVision\WvDeepltranslate\ClientInterface;
use WebVision\WvDeepltranslate\Domain\Repository\GlossaryRepository;
use WebVision\WvDeepltranslate\Exception\ApiKeyNotSetException;
Expand Down Expand Up @@ -72,16 +68,9 @@ public function translateRequest(
$response = $this->client->translate($content, $sourceLanguage, $targetLanguage, $glossaryId);

if ($response === null) {
if (!Environment::isCli() || !Environment::getContext()->isTesting()) {
$flashMessage = GeneralUtility::makeInstance(
FlashMessage::class,
'Translation not successful',
'',
-1
);
GeneralUtility::makeInstance(FlashMessageService::class)
->getMessageQueueByIdentifier()
->addMessage($flashMessage);
// @todo Can be replaced with `$this->logger?->` when TYPO3 v11 and therefore PHP 7.4/8.0 support is dropped.
if ($this->logger !== null) {
$this->logger->warning('Translation not successful');
}
}

Expand Down

0 comments on commit 4e5be02

Please sign in to comment.