Skip to content

Commit

Permalink
Compatibility v12 (#5)
Browse files Browse the repository at this point in the history
* [WIP] Compatibility v12
* Convert to PHP 7.4
* Code migrations
* Update testing framework
* Update typoscript lint
* Update packages
* Update packages
* Update packages
* Apply php-cs-fixer
* Update ci
* Update ci
* Fix some issues
* Use latest test framework
* Install testing framework bridge
* Update README.md
* Fix phpstan
* Fix unit test
* Update extension icon
  • Loading branch information
r3h6 authored May 31, 2023
1 parent 78b0d74 commit 117850e
Show file tree
Hide file tree
Showing 25 changed files with 246 additions and 192 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ jobs:
strategy:
matrix:
env:
- { PHP: '7.4', TYPO3_VERSION: ^10.4 }
- { PHP: '7.3', TYPO3_VERSION: ^10.4 }
- { PHP: '7.2', TYPO3_VERSION: ^10.4 }
- { PHP: '8.2', TYPO3_VERSION: ^12.3 }
- { PHP: '8.1', TYPO3_VERSION: ^12.3 }
- { PHP: '8.2', TYPO3_VERSION: ^11.5 }
- { PHP: '8.1', TYPO3_VERSION: ^11.5 }
- { PHP: '8.0', TYPO3_VERSION: ^11.5 }
Expand Down
2 changes: 1 addition & 1 deletion Build/Scripts/runTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ THIS_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
cd "$THIS_SCRIPT_DIR" || exit 1
cd ../Docker || exit 1

export PHP=${PHP:-7.4}
export PHP=${PHP:-8.1}
export DOCKER_PHP_IMAGE=`echo "typo3/core-testing-php${PHP}" | sed -e 's/\.//'`
export ROOT_DIR=`readlink -f ${PWD}/../../`
export HOST_UID=`id -u`
Expand Down
3 changes: 3 additions & 0 deletions Classes/Command/CreateXliffCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class CreateXliffCommand extends Command
*/
protected $localizationService;

/**
* @phpstan-return void
*/
protected function configure()
{
$this
Expand Down
132 changes: 61 additions & 71 deletions Classes/Controller/FormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@

namespace R3H6\FormTranslator\Controller;

use Psr\Http\Message\ResponseInterface;
use R3H6\FormTranslator\Service\FormService;
use R3H6\FormTranslator\Service\LocalizationService;
use R3H6\FormTranslator\Service\SiteLanguageService;
use R3H6\FormTranslator\Translation\ItemCollection;
use TYPO3\CMS\Backend\Template\Components\ButtonBar;
use TYPO3\CMS\Backend\View\BackendTemplateView;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
use TYPO3\CMS\Backend\Template\ModuleTemplateFactory;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
use TYPO3\CMS\Core\Http\Uri;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
Expand All @@ -23,45 +26,49 @@
*/
class FormController extends ActionController
{
/**
* @var BackendTemplateView
*/
protected $view;

protected $defaultViewObjectName = BackendTemplateView::class;

/**
* @var SiteLanguageService
*/
protected $siteLanguageService;

/**
* @var FormService
*/
protected $formService;

/**
* @var LocalizationService
*/
protected $localizationService;

/**
* @var FrontendInterface
*/
protected $l10nCache;

public function indexAction(): void
protected SiteLanguageService $siteLanguageService;
protected FormService $formService;
protected LocalizationService $localizationService;
protected FrontendInterface $l10nCache;
protected ModuleTemplateFactory $moduleTemplateFactory;
protected IconFactory $iconFactory;
protected PageRenderer $pageRenderer;

public function __construct(
SiteLanguageService $siteLanguageService,
FormService $formService,
LocalizationService $localizationService,
FrontendInterface $l10nCache,
ModuleTemplateFactory $moduleTemplateFactory,
IconFactory $iconFactory,
PageRenderer $pageRenderer
) {
$this->siteLanguageService = $siteLanguageService;
$this->formService = $formService;
$this->localizationService = $localizationService;
$this->l10nCache = $l10nCache;
$this->moduleTemplateFactory = $moduleTemplateFactory;
$this->iconFactory = $iconFactory;
$this->pageRenderer = $pageRenderer;
}

public function indexAction(): ResponseInterface
{
$this->view->assign('siteLanguages', $this->siteLanguageService->findAll());
$this->view->assign('forms', $this->formService->listForms());

$buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar();
$this->addReloadButtonToButtonBar($buttonBar);
$this->addShortcutButtonToButtonBar($buttonBar, LocalizationUtility::translate('mod.title.index', 'FormTranslator'));
$moduleTemplate = $this->moduleTemplateFactory->create($this->request);
$moduleTemplate->setContent($this->view->render());
$this->addReloadButtonToButtonBar($moduleTemplate);
$this->addShortcutButtonToButtonBar($moduleTemplate, LocalizationUtility::translate('mod.title.index', 'FormTranslator'));
return $this->htmlResponse($moduleTemplate->renderContent());
}

public function localizeAction(string $persistenceIdentifier, SiteLanguage $siteLanguage): void
public function localizeAction(string $persistenceIdentifier, SiteLanguage $siteLanguage): ResponseInterface
{
$this->pageRenderer->loadRequireJsModule('TYPO3/CMS/FormTranslator/Mod');
$this->pageRenderer->addCssFile('EXT:form_translator/Resources/Public/StyleSheets/Mod.css');

$docTitle = LocalizationUtility::translate('mod.title.localize', 'FormTranslator', [
$this->formService->getTitle($persistenceIdentifier),
$siteLanguage->getTitle(),
Expand All @@ -72,16 +79,19 @@ public function localizeAction(string $persistenceIdentifier, SiteLanguage $site
$this->view->assign('siteLanguage', $siteLanguage);
$this->view->assign('persistenceIdentifier', $persistenceIdentifier);

$buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar();
$this->addReloadButtonToButtonBar($buttonBar);
$this->addShortcutButtonToButtonBar($buttonBar, $docTitle);
$moduleTemplate = $this->moduleTemplateFactory->create($this->request);
$moduleTemplate->setContent($this->view->render());

$this->addReloadButtonToButtonBar($moduleTemplate);
$this->addShortcutButtonToButtonBar($moduleTemplate, $docTitle);

$buttonBar = $moduleTemplate->getDocHeaderComponent()->getButtonBar();
$buttonBar->addButton(
$buttonBar->makeLinkButton()
->setTitle($this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:close'))
->setShowLabelText(true)
->setHref($this->uriBuilder->reset()->uriFor('index'))
->setIcon($this->view->getModuleTemplate()->getIconFactory()->getIcon('actions-close', Icon::SIZE_SMALL)),
->setIcon($this->iconFactory->getIcon('actions-close', Icon::SIZE_SMALL)),
ButtonBar::BUTTON_POSITION_LEFT,
1
);
Expand All @@ -91,13 +101,15 @@ public function localizeAction(string $persistenceIdentifier, SiteLanguage $site
->setShowLabelText(true)
->setHref('#')
->setDataAttributes(['save' => '#LocalizationForm'])
->setIcon($this->view->getModuleTemplate()->getIconFactory()->getIcon('actions-save', Icon::SIZE_SMALL)),
->setIcon($this->iconFactory->getIcon('actions-save', Icon::SIZE_SMALL)),
ButtonBar::BUTTON_POSITION_LEFT,
2
);

return $this->htmlResponse($moduleTemplate->renderContent());
}

public function saveAction(string $persistenceIdentifier, SiteLanguage $siteLanguage, ItemCollection $items): void
public function saveAction(string $persistenceIdentifier, SiteLanguage $siteLanguage, ItemCollection $items): ResponseInterface
{
$locallangFile = $this->formService->getLocallangFileFromPersistenceIdentifier($persistenceIdentifier);
$this->localizationService->saveXliff($locallangFile, $siteLanguage, $items);
Expand All @@ -106,27 +118,7 @@ public function saveAction(string $persistenceIdentifier, SiteLanguage $siteLang
$this->formService->addTranslationFile($persistenceIdentifier, $locallangFile);
}
$this->l10nCache->flush();
$this->redirect('localize', null, null, ['persistenceIdentifier' => $persistenceIdentifier, 'siteLanguage' => $siteLanguage->getLanguageId()]);
}

public function injectSiteLanguageService(SiteLanguageService $siteLanguageService): void
{
$this->siteLanguageService = $siteLanguageService;
}

public function injectFormService(FormService $formService): void
{
$this->formService = $formService;
}

public function injectLocalizationService(LocalizationService $localizationService): void
{
$this->localizationService = $localizationService;
}

public function injectL10nCache(FrontendInterface $l10nCache): void
{
$this->l10nCache = $l10nCache;
return $this->redirect('localize', null, null, ['persistenceIdentifier' => $persistenceIdentifier, 'siteLanguage' => $siteLanguage->getLanguageId()]);
}

protected function getLanguageService(): LanguageService
Expand All @@ -139,36 +131,34 @@ protected function getBackendUser(): BackendUserAuthentication
return $GLOBALS['BE_USER'];
}

protected function addReloadButtonToButtonBar(ButtonBar $buttonBar): void
protected function addReloadButtonToButtonBar(ModuleTemplate $moduleTemplate): void
{
$buttonBar = $moduleTemplate->getDocHeaderComponent()->getButtonBar();
/** @var string $requestUri */
$requestUri = GeneralUtility::getIndpEnv('REQUEST_URI');
$buttonBar->addButton(
$buttonBar->makeLinkButton()
->setHref($requestUri)
->setTitle($this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.reload'))
->setIcon($this->view->getModuleTemplate()->getIconFactory()->getIcon('actions-refresh', Icon::SIZE_SMALL)),
->setIcon($this->iconFactory->getIcon('actions-refresh', Icon::SIZE_SMALL)),
ButtonBar::BUTTON_POSITION_RIGHT,
1
);
}

protected function addShortcutButtonToButtonBar(ButtonBar $buttonBar, string $title): void
protected function addShortcutButtonToButtonBar(ModuleTemplate $moduleTemplate, string $title): void
{
$buttonBar = $moduleTemplate->getDocHeaderComponent()->getButtonBar();
$mayMakeShortcut = $this->getBackendUser()->mayMakeShortcut();
if ($mayMakeShortcut) {
/** @var string $requestUri */
$requestUri = GeneralUtility::getIndpEnv('REQUEST_URI');
$uri = new Uri($requestUri);
$queryParams = [];
parse_str($uri->getQuery(), $queryParams);
parse_str($this->request->getUri()->getQuery(), $queryParams);
$getVars = array_diff(array_keys($queryParams), ['token']);

$moduleName = $this->controllerContext->getRequest()->getPluginName();
$shortcutButton = $buttonBar->makeShortcutButton()
->setModuleName($moduleName)
->setRouteIdentifier('web_FormTranslator')
->setDisplayName($title)
->setGetVariables($getVars);
->setArguments($getVars);
$buttonBar->addButton($shortcutButton, ButtonBar::BUTTON_POSITION_RIGHT);
}
}
Expand Down
15 changes: 3 additions & 12 deletions Classes/Controller/TranslationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,11 @@ class TranslationController implements LoggerAwareInterface
{
use LoggerAwareTrait;

/**
* @var TranslationServiceInterface
*/
protected $translationService;
protected TranslationServiceInterface $translationService;

/**
* @var SiteLanguageService
*/
protected $siteLanguageService;
protected SiteLanguageService $siteLanguageService;

/**
* @var MemoryTranslationService
*/
protected $memoryTranslationService;
protected MemoryTranslationService $memoryTranslationService;

public function __construct(MemoryTranslationService $memoryTranslationService, TranslationServiceInterface $translationService, SiteLanguageService $siteLanguageService)
{
Expand Down
4 changes: 1 addition & 3 deletions Classes/EventListener/RemoveEmptyItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ class RemoveEmptyItems
{
public function __invoke(AfterParseFormEvent $event): void
{
$event->setItems(array_filter($event->getItems(), function ($value) {
return $value !== '';
}));
$event->setItems(array_filter($event->getItems(), fn ($value): bool => $value !== ''));
}
}
12 changes: 5 additions & 7 deletions Classes/Parser/FormDefinitionLabelsParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

namespace R3H6\FormTranslator\Parser;

use Flow\JSONPath\JSONPath;
use Psr\EventDispatcher\EventDispatcherInterface;
use R3H6\FormTranslator\Event\AfterParseFormEvent;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class FormDefinitionLabelsParser
{
/**
* @var EventDispatcherInterface
*/
protected $dispatcher;
protected EventDispatcherInterface $dispatcher;

/**
* @var array<string, string>
Expand Down Expand Up @@ -50,14 +48,14 @@ public function parse(array $form): array
{
$items = [];

$json = new \Flow\JSONPath\JSONPath($form);
$json = new JSONPath($form);
$formIdentifier = $form['identifier'];

$items['element.' . $formIdentifier . '.renderingOptions.submitButtonLabel'] = $form['renderingOptions']['submitButtonLabel'];

$finishers = $json->find('..finishers[*]')->getData();
foreach ($finishers as $finisher) {
$sub = new \Flow\JSONPath\JSONPath(['finisher' => $finisher]);
$sub = new JSONPath(['finisher' => $finisher]);
$identifier = $finisher['identifier'];
foreach ($this->labels as $path => $id) {
$value = $sub->find($path)->getData();
Expand All @@ -70,7 +68,7 @@ public function parse(array $form): array

$renderables = $json->find('..renderables[*]')->getData();
foreach ($renderables as $renderable) {
$sub = new \Flow\JSONPath\JSONPath(['renderable' => $renderable]);
$sub = new JSONPath(['renderable' => $renderable]);
$identifier = $renderable['identifier'];
foreach ($this->labels as $path => $id) {
$value = $sub->find($path)->getData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ItemCollectionConverter extends AbstractTypeConverter
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function convertFrom($source, string $targetType, array $convertedChildProperties = [], ?PropertyMappingConfigurationInterface $configuration = null)
public function convertFrom($source, string $targetType, array $convertedChildProperties = [], ?PropertyMappingConfigurationInterface $configuration = null): ItemCollection
{
$items = new ItemCollection();
foreach ($source as $sourceItem) {
Expand Down
26 changes: 7 additions & 19 deletions Classes/Service/FormService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,13 @@ class FormService
{
protected const TRANSLATION_FILE_KEY = 99;

/**
* @var FormDefinitionLabelsParser
*/
protected $formDefinitionLabelsParser;

/**
* @var LocalizationFactory
*/
protected $localizationFactory;

/**
* @var FormPersistenceManagerInterface
*/
protected $formPersistenceManager;

/**
* @var string
*/
protected $locallangPath;
protected FormDefinitionLabelsParser $formDefinitionLabelsParser;

protected LocalizationFactory $localizationFactory;

protected FormPersistenceManagerInterface $formPersistenceManager;

protected string $locallangPath;

public function __construct(
FormDefinitionLabelsParser $formDefinitionLabelsParser,
Expand Down
Loading

0 comments on commit 117850e

Please sign in to comment.