Skip to content

Commit

Permalink
Compatibility v13 (#16)
Browse files Browse the repository at this point in the history
[TASK] Compatibility with v13
  • Loading branch information
r3h6 authored Oct 16, 2024
1 parent f202eb4 commit 40151ca
Show file tree
Hide file tree
Showing 69 changed files with 1,418 additions and 710 deletions.
26 changes: 26 additions & 0 deletions .ddev/commands/web/runTests
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash


## Description: Run unit or functional tests
## Usage: runTests [command]
## Example: "ddev runTests [command]"

suite=$1
args="${@:2}"

# Unit tests
if [ "$suite" == "unit" ]; then
echo "Running unit tests"
.Build/bin/phpunit -c .Build/vendor/typo3/testing-framework/Resources/Core/Build/UnitTests.xml Tests/Unit/ $args
exit 0
fi

# Functional tests
if [ "$suite" == "functional" ]; then
echo "Running functional tests"
.Build/bin/phpunit -c .Build/vendor/typo3/testing-framework/Resources/Core/Build/FunctionalTests.xml Tests/Functional/ $args
exit 0
fi

echo "Please provide a valid test suite: unit or functional"
exit 1
8 changes: 8 additions & 0 deletions .ddev/commands/web/typo3
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash


## Description: Run the TYPO3 CLI in the web container
## Usage: typo3 [command]
## Example: "ddev typo3 [command]"

.Build/bin/typo3 "$@"
7 changes: 3 additions & 4 deletions .ddev/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ nfs_mount_enabled: false
mutagen_enabled: false
use_dns_when_possible: true
composer_version: "2"
web_environment: []
nodejs_version: "16"

web_environment:
- TYPO3_CONTEXT=Development
- typo3DatabaseDriver=pdo_sqlite
# Key features of ddev's config.yaml:

# name: <projectname> # Name of the project, automatically provides
Expand Down Expand Up @@ -185,8 +186,6 @@ nodejs_version: "16"
# In this case the user must provide all such settings.

# You can inject environment variables into the web container with:
web_environment:
- TYPO3_CONTEXT=Development

# no_project_mount: false
# (Experimental) If true, ddev will not mount the project into the web container;
Expand Down
22 changes: 7 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ jobs:
strategy:
matrix:
env:
- { PHP: '8.3', TYPO3_VERSION: ^13.4 }
- { PHP: '8.2', TYPO3_VERSION: ^13.4 }
- { PHP: '8.3', TYPO3_VERSION: ^12.4 }
- { PHP: '8.2', TYPO3_VERSION: ^12.4 }
- { PHP: '8.1', TYPO3_VERSION: ^12.4 }
- { PHP: '8.2', TYPO3_VERSION: ^11.5 }
- { PHP: '8.1', TYPO3_VERSION: ^11.5 }
- { PHP: '8.0', TYPO3_VERSION: ^11.5 }
- { PHP: '7.4', TYPO3_VERSION: ^11.5 }

env: ${{ matrix.env }}

Expand All @@ -27,17 +25,11 @@ jobs:
- name: Install
run: ./Build/Scripts/runTests.sh composer require typo3/cms-core="${TYPO3_VERSION}" --no-suggest

- name: Lint PHP
run: ./Build/Scripts/runTests.sh composer ci:php:lint

- name: PHP Coding Standards Fixer
run: ./Build/Scripts/runTests.sh composer ci:php:cs

- name: PHPStan
run: ./Build/Scripts/runTests.sh composer ci:php:stan

# - name: PHP Mess Detector
# run: ./Build/Scripts/runTests.sh composer ci:php:md
- name: Lint
run: ./Build/Scripts/runTests.sh composer ci:static

- name: Unit tests
run: ./Build/Scripts/runTests.sh unit

- name: Functional tests
run: ./Build/Scripts/runTests.sh functional
4 changes: 4 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<?php

$config = \TYPO3\CodingStandards\CsFixerConfig::create();
$config->addRules([
'declare_strict_types' => true,
]);
$config->getFinder()->in(__DIR__)->exclude([
'.Build',
'config/system',
'Resources/Private/Php'
]);

Expand Down
14 changes: 14 additions & 0 deletions Build/Scripts/xliff-lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env php
<?php

include_once __DIR__ . '/../../.Build/vendor/autoload.php';

use Symfony\Component\Console\Application;
use Symfony\Component\Translation\Command\XliffLintCommand;
use Symfony\Component\Yaml\Command\LintCommand;

$application = new Application();
$application->add(new XliffLintCommand(null, null, null, false));
$application->add(new LintCommand());

exit($application->run());
39 changes: 14 additions & 25 deletions Classes/Command/CreateXliffCommand.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
<?php

declare(strict_types=1);

namespace R3H6\FormTranslator\Command;

use R3H6\FormTranslator\Service\FormService;
use R3H6\FormTranslator\Service\LocalizationService;
use R3H6\FormTranslator\Translation\Dto\Typo3Language;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use TYPO3\CMS\Core\Http\Uri;
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class CreateXliffCommand extends Command
{
/**
* @var FormService
*/
protected $formService;

/**
* @var LocalizationService
*/
protected $localizationService;
public function __construct(
protected readonly FormService $formService,
protected readonly LocalizationService $localizationService,
) {
parent::__construct();
}

/**
* @phpstan-return void
Expand All @@ -39,18 +38,18 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output): int
{
$formIdentifier = $input->getArgument('formIdentifier');
$siteLanguage = new SiteLanguage(0, 'en_US.UTF-8', new Uri('/'), []);
$items = $this->formService->getItems($formIdentifier, $siteLanguage);
$language = new Typo3Language('default', 'English', 'gb');
$items = $this->formService->getItems($formIdentifier, $language);

$xliff = $this->localizationService->renderXliff([
'items' => $items,
'siteLanguage' => $siteLanguage,
'language' => $language,
'originalFile' => '',
]);

$outputOption = $input->getOption('output');
if ($outputOption) {
if (file_put_contents($outputOption, $xliff) === false) {
if (GeneralUtility::writeFile($outputOption, $xliff) === false) {
return Command::FAILURE;
}
return Command::SUCCESS;
Expand All @@ -59,14 +58,4 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output->writeln($xliff);
return Command::SUCCESS;
}

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

public function injectLocalizationService(LocalizationService $localizationService): void
{
$this->localizationService = $localizationService;
}
}
120 changes: 49 additions & 71 deletions Classes/Controller/FormController.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<?php

declare(strict_types=1);

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\Service\Typo3LanguageService;
use R3H6\FormTranslator\Translation\Dto\Typo3Language;
use R3H6\FormTranslator\Translation\ItemCollection;
use TYPO3\CMS\Backend\Template\Components\ButtonBar;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
Expand All @@ -16,74 +19,48 @@
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;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class FormController extends ActionController
{
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;
}
protected Typo3LanguageService $languageService,
protected FormService $formService,
protected LocalizationService $localizationService,
protected FrontendInterface $l10nCache,
protected ModuleTemplateFactory $moduleTemplateFactory,
protected IconFactory $iconFactory,
protected PageRenderer $pageRenderer,
) {}

public function indexAction(): ResponseInterface
{
$this->view->assign('siteLanguages', $this->siteLanguageService->findAll());
$this->view->assign('forms', $this->formService->listForms());
$title = 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());
$moduleTemplate = $this->initializeModuleTemplate($title);
$moduleTemplate->assign('languages', $this->languageService->findAll());
$moduleTemplate->assign('forms', $this->formService->listForms());
$moduleTemplate->assign('title', $title);

return $moduleTemplate->renderResponse('Form/Index');
}

public function localizeAction(string $persistenceIdentifier, SiteLanguage $siteLanguage): ResponseInterface
public function localizeAction(string $persistenceIdentifier, Typo3Language $language): ResponseInterface
{
$this->pageRenderer->loadRequireJsModule('TYPO3/CMS/FormTranslator/Mod');
$this->pageRenderer->loadJavaScriptModule('@r3h6/form-translator/Mod.js');
$this->pageRenderer->addCssFile('EXT:form_translator/Resources/Public/StyleSheets/Mod.css');

$docTitle = LocalizationUtility::translate('mod.title.localize', 'FormTranslator', [
$title = LocalizationUtility::translate('mod.title.localize', 'FormTranslator', [
$this->formService->getTitle($persistenceIdentifier),
$siteLanguage->getTitle(),
$language->getTitle(),
]);

$this->view->assign('docTitle', $docTitle);
$this->view->assign('items', $this->formService->getItems($persistenceIdentifier, $siteLanguage));
$this->view->assign('siteLanguage', $siteLanguage);
$this->view->assign('persistenceIdentifier', $persistenceIdentifier);

$moduleTemplate = $this->moduleTemplateFactory->create($this->request);
$moduleTemplate->setContent($this->view->render());

$this->addReloadButtonToButtonBar($moduleTemplate);
$this->addShortcutButtonToButtonBar($moduleTemplate, $docTitle);
$moduleTemplate = $this->initializeModuleTemplate($title);
$moduleTemplate->assign('title', $title);
$moduleTemplate->assign('items', $this->formService->getItems($persistenceIdentifier, $language));
$moduleTemplate->assign('language', $language);
$moduleTemplate->assign('persistenceIdentifier', $persistenceIdentifier);

$buttonBar = $moduleTemplate->getDocHeaderComponent()->getButtonBar();
$buttonBar->addButton(
Expand All @@ -106,36 +83,29 @@ public function localizeAction(string $persistenceIdentifier, SiteLanguage $site
2
);

return $this->htmlResponse($moduleTemplate->renderContent());
return $moduleTemplate->renderResponse('Form/Localize');
}

public function saveAction(string $persistenceIdentifier, SiteLanguage $siteLanguage, ItemCollection $items): ResponseInterface
public function saveAction(string $persistenceIdentifier, Typo3Language $language, ItemCollection $items): ResponseInterface
{
$locallangFile = $this->formService->getLocallangFileFromPersistenceIdentifier($persistenceIdentifier);
$this->localizationService->saveXliff($locallangFile, $siteLanguage, $items);
$this->localizationService->saveXliff($locallangFile, $language, $items);
$this->addFlashMessage('Saved translation to ' . $locallangFile);
if ($this->formService->isWritable($persistenceIdentifier)) {
$this->formService->addTranslationFile($persistenceIdentifier, $locallangFile);
}
$this->l10nCache->flush();
return $this->redirect('localize', null, null, ['persistenceIdentifier' => $persistenceIdentifier, 'siteLanguage' => $siteLanguage->getLanguageId()]);
return $this->redirect('localize', null, null, ['persistenceIdentifier' => $persistenceIdentifier, 'language' => $language->getTypo3Language()]);
}

protected function getLanguageService(): LanguageService
protected function initializeModuleTemplate(string $title): ModuleTemplate
{
return $GLOBALS['LANG'];
}

protected function getBackendUser(): BackendUserAuthentication
{
return $GLOBALS['BE_USER'];
}
$moduleTemplate = $this->moduleTemplateFactory->create($this->request);
$moduleTemplate->setTitle($title);

protected function addReloadButtonToButtonBar(ModuleTemplate $moduleTemplate): void
{
$buttonBar = $moduleTemplate->getDocHeaderComponent()->getButtonBar();
/** @var string $requestUri */
$requestUri = GeneralUtility::getIndpEnv('REQUEST_URI');

$requestUri = (string)$this->request->getUri();
$buttonBar->addButton(
$buttonBar->makeLinkButton()
->setHref($requestUri)
Expand All @@ -144,11 +114,7 @@ protected function addReloadButtonToButtonBar(ModuleTemplate $moduleTemplate): v
ButtonBar::BUTTON_POSITION_RIGHT,
1
);
}

protected function addShortcutButtonToButtonBar(ModuleTemplate $moduleTemplate, string $title): void
{
$buttonBar = $moduleTemplate->getDocHeaderComponent()->getButtonBar();
$mayMakeShortcut = $this->getBackendUser()->mayMakeShortcut();
if ($mayMakeShortcut) {
$queryParams = [];
Expand All @@ -161,5 +127,17 @@ protected function addShortcutButtonToButtonBar(ModuleTemplate $moduleTemplate,
->setArguments($getVars);
$buttonBar->addButton($shortcutButton, ButtonBar::BUTTON_POSITION_RIGHT);
}

return $moduleTemplate;
}

protected function getLanguageService(): LanguageService
{
return $GLOBALS['LANG'];
}

protected function getBackendUser(): BackendUserAuthentication
{
return $GLOBALS['BE_USER'];
}
}
Loading

0 comments on commit 40151ca

Please sign in to comment.