Skip to content

Commit

Permalink
[TASK] Clean up language service usage
Browse files Browse the repository at this point in the history
  • Loading branch information
fsuter committed Jan 10, 2025
1 parent d82f89a commit 007de75
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
20 changes: 13 additions & 7 deletions Classes/Task/AutomatedSyncAdditionalFieldProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

use Cobweb\ExternalImport\Domain\Model\ConfigurationKey;
use Cobweb\ExternalImport\Domain\Repository\ConfigurationRepository;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface;
use TYPO3\CMS\Scheduler\Controller\SchedulerModuleController;
Expand Down Expand Up @@ -75,7 +76,7 @@ public function getAdditionalFields(array &$taskInfo, $task, SchedulerModuleCont
}
// Add "all" selector
$fieldCode .= '<option value="all"' . $selected . '>' .
$GLOBALS['LANG']->sL('LLL:EXT:external_import/Resources/Private/Language/ExternalImport.xlf:all') .
$this->getLanguageService()->sL('LLL:EXT:external_import/Resources/Private/Language/ExternalImport.xlf:all') .
'</option>';
// Get configuration repository for fetching values
$configurationRepository = GeneralUtility::makeInstance(ConfigurationRepository::class);
Expand All @@ -84,7 +85,7 @@ public function getAdditionalFields(array &$taskInfo, $task, SchedulerModuleCont
$groups = $configurationRepository->findAllGroups();
if (count($groups) > 0) {
$fieldCode .= '<optgroup label="' .
$GLOBALS['LANG']->sL('LLL:EXT:external_import/Resources/Private/Language/ExternalImport.xlf:options.groups') .
$this->getLanguageService()->sL('LLL:EXT:external_import/Resources/Private/Language/ExternalImport.xlf:options.groups') .
'">';
foreach ($groups as $group) {
$id = 'group:' . $group;
Expand All @@ -101,19 +102,19 @@ public function getAdditionalFields(array &$taskInfo, $task, SchedulerModuleCont
$configurations = $configurationRepository->findBySync(true);
if (count($configurations) > 0) {
$fieldCode .= '<optgroup label="' .
$GLOBALS['LANG']->sL('LLL:EXT:external_import/Resources/Private/Language/ExternalImport.xlf:options.configurations') .
$this->getLanguageService()->sL('LLL:EXT:external_import/Resources/Private/Language/ExternalImport.xlf:options.configurations') .
'">';
foreach ($configurations as $configuration) {
$id = $configuration['id'];
$selected = '';
if ($taskInfo[self::$itemFieldName] === $id) {
$selected = ' selected="selected"';
}
$label = $GLOBALS['LANG']->sL('LLL:EXT:external_import/Resources/Private/Language/ExternalImport.xlf:table') .
$label = $this->getLanguageService()->sL('LLL:EXT:external_import/Resources/Private/Language/ExternalImport.xlf:table') .
': ' . $configuration['table'];
$label .= ', ' . $GLOBALS['LANG']->sL('LLL:EXT:external_import/Resources/Private/Language/ExternalImport.xlf:index') .
$label .= ', ' . $this->getLanguageService()->sL('LLL:EXT:external_import/Resources/Private/Language/ExternalImport.xlf:index') .
': ' . $configuration['index'];
$label .= ', ' . $GLOBALS['LANG']->sL('LLL:EXT:external_import/Resources/Private/Language/ExternalImport.xlf:priority') .
$label .= ', ' . $this->getLanguageService()->sL('LLL:EXT:external_import/Resources/Private/Language/ExternalImport.xlf:priority') .
': ' . $configuration['priority'];
$fieldCode .= '<option value="' . $id . '"' . $selected . '>' . $label . '</option>';
}
Expand Down Expand Up @@ -170,7 +171,7 @@ public function validateAdditionalFields(array &$submittedData, SchedulerModuleC
public function saveAdditionalFields(array $submittedData, AbstractTask $task): void
{
$fieldValue = $submittedData[self::$itemFieldName];
if ($fieldValue === 'all' || strpos($fieldValue, 'group:') === 0) {
if ($fieldValue === 'all' || str_starts_with($fieldValue, 'group:')) {
$task->table = $fieldValue;
$task->index = 0;
} else {
Expand All @@ -181,4 +182,9 @@ public function saveAdditionalFields(array $submittedData, AbstractTask $task):
}
$task->storage = (int)$submittedData[self::$storageFieldName];
}

protected function getLanguageService(): ?LanguageService
{
return $GLOBALS['LANG'] ?? null;
}
}
11 changes: 6 additions & 5 deletions Classes/Task/AutomatedSyncTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use Cobweb\ExternalImport\Importer;
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
use TYPO3\CMS\Scheduler\Task\AbstractTask;

/**
Expand Down Expand Up @@ -145,13 +144,13 @@ public function execute(): bool
public function getAdditionalInformation(): string
{
if ($this->table === 'all') {
$info = LocalizationUtility::translate(
$info = $this->getLanguageService()->sL(
'LLL:EXT:external_import/Resources/Private/Language/ExternalImport.xlf:allTables'
);
} elseif (strpos($this->table, 'group:') === 0) {
$group = substr($this->table, 6);
$info = sprintf(
LocalizationUtility::translate(
$this->getLanguageService()->sL(
'LLL:EXT:external_import/Resources/Private/Language/ExternalImport.xlf:selectedGroup'
),
$group
Expand All @@ -161,7 +160,7 @@ public function getAdditionalInformation(): string
$configurationRepository = GeneralUtility::makeInstance(ConfigurationRepository::class);
$configuration = $configurationRepository->findConfigurationObject($this->table, $this->index);
$info = sprintf(
LocalizationUtility::translate(
$this->getLanguageService()->sL(
'LLL:EXT:external_import/Resources/Private/Language/ExternalImport.xlf:tableIndexAndPriority'
),
$this->table,
Expand All @@ -177,7 +176,9 @@ public function getAdditionalInformation(): string
$info .= ' / ';
}
$info .= sprintf(
$this->getLanguageService()->sL('LLL:EXT:external_import/Resources/Private/Language/ExternalImport.xlf:overrideStoragePid'),
$this->getLanguageService()->sL(
'LLL:EXT:external_import/Resources/Private/Language/ExternalImport.xlf:overrideStoragePid'
),
$this->storage
);
}
Expand Down

0 comments on commit 007de75

Please sign in to comment.