Skip to content

Commit 24bce76

Browse files
committed
[TASK] Implement page view override
In addition to the base functionality for JavaScript, this adds the default override of the PageBackendView partial. Move the extension enabled ViewHelper to deepl_base. Register respective Event Listeners for generating the translation dropdowns for available languages.
1 parent 752631c commit 24bce76

File tree

8 files changed

+125
-329
lines changed

8 files changed

+125
-329
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace WebVision\Deepltranslate\Core\Event\Listener;
6+
7+
use TYPO3\CMS\Backend\View\PageLayoutContext;
8+
use WebVision\Deepl\Base\Event\ViewHelpers\ModifyInjectVariablesViewHelperEvent;
9+
use WebVision\Deepltranslate\Core\Utility\DeeplBackendUtility;
10+
11+
final class RenderPageViewLocalizationDropdownEventListener
12+
{
13+
public function __invoke(ModifyInjectVariablesViewHelperEvent $event): void
14+
{
15+
if ($event->getIdentifier() !== 'languageTranslationDropdown') {
16+
return;
17+
}
18+
$translationPartials = $event->getLocalVariableProvider()->get('translationPartials');
19+
if ($translationPartials === null) {
20+
$translationPartials = [];
21+
}
22+
$translationPartials[20] = 'Translation/DeeplTranslationDropdown';
23+
$event->getLocalVariableProvider()->add('translationPartials', $translationPartials);
24+
25+
$deeplTranslateLanguages = [];
26+
$event->getLocalVariableProvider()->add('deeplLanguages', []);
27+
/** @var PageLayoutContext|null $context */
28+
$context = $event->getGlobalVariableProvider()->get('context');
29+
if ($context === null) {
30+
return;
31+
}
32+
33+
foreach ($context->getSiteLanguages() as $siteLanguage) {
34+
if (
35+
$siteLanguage->getLanguageId() != -1
36+
&& $siteLanguage->getLanguageId() != 0
37+
) {
38+
if (!DeeplBackendUtility::checkCanBeTranslated(
39+
$context->getPageId(),
40+
$siteLanguage->getLanguageId()
41+
)
42+
) {
43+
continue;
44+
}
45+
$deeplTranslateLanguages[$siteLanguage->getTitle()] = $siteLanguage->getLanguageId();
46+
}
47+
}
48+
if ($deeplTranslateLanguages === []) {
49+
return;
50+
}
51+
$options = [];
52+
foreach ($context->getNewLanguageOptions() as $key => $possibleLanguage) {
53+
if ($key === 0) {
54+
continue;
55+
}
56+
if (!array_key_exists($possibleLanguage, $deeplTranslateLanguages)) {
57+
continue;
58+
}
59+
$parameters = [
60+
'justLocalized' => 'pages:' . $context->getPageId() . ':' . $deeplTranslateLanguages[$possibleLanguage],
61+
'returnUrl' => $GLOBALS['TYPO3_REQUEST']->getAttribute('normalizedParams')->getRequestUri(),
62+
];
63+
64+
$redirectUrl = DeeplBackendUtility::buildBackendRoute('record_edit', $parameters);
65+
$params = [];
66+
$params['redirect'] = $redirectUrl;
67+
$params['cmd']['pages'][$context->getPageId()]['deepltranslate'] = $deeplTranslateLanguages[$possibleLanguage];
68+
69+
$targetUrl = DeeplBackendUtility::buildBackendRoute('tce_db', $params);
70+
71+
$options[$targetUrl] = $possibleLanguage;
72+
}
73+
74+
if ($options === []) {
75+
return;
76+
}
77+
$event->getLocalVariableProvider()->add('deeplLanguages', $options);
78+
}
79+
}

Classes/ViewHelpers/Be/ExtensionActiveViewHelper.php

Lines changed: 0 additions & 41 deletions
This file was deleted.

Classes/ViewHelpers/DeeplTranslateViewHelper.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,18 @@
77
use TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException;
88
use TYPO3\CMS\Backend\View\PageLayoutContext;
99
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
10+
use WebVision\Deepl\Base\Event\ViewHelpers\ModifyInjectVariablesViewHelperEvent;
11+
use WebVision\Deepltranslate\Core\Event\Listener\RenderPageViewLocalizationDropdownEventListener;
1012
use WebVision\Deepltranslate\Core\Utility\DeeplBackendUtility;
1113

14+
/**
15+
* @deprecated Will be removed in the next major release
16+
*
17+
* This viewHelper is deprecated, as the registration is now done by the deepl_base
18+
* event and directly registered during the EventListener invocation.
19+
* @see RenderPageViewLocalizationDropdownEventListener
20+
* @see ModifyInjectVariablesViewHelperEvent
21+
*/
1222
final class DeeplTranslateViewHelper extends AbstractViewHelper
1323
{
1424

@@ -28,6 +38,10 @@ public function initializeArguments(): void
2838
*/
2939
public function render(): array
3040
{
41+
trigger_error(
42+
'This ViewHelper is deprecated and should no longer be used',
43+
E_USER_DEPRECATED
44+
);
3145
$options = [];
3246
/** @var PageLayoutContext $context */
3347
$context = $this->arguments['context'];

Configuration/Services.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,10 @@ services:
6767
identifier: 'deepltranslate-core/deepltranslate-core-localization-modes-process'
6868
event: WebVision\Deepl\Base\Event\LocalizationProcessPrepareDataHandlerCommandMapEvent
6969
after: 'deepl-base/process-default-typo3-localization-modes'
70+
71+
WebVision\Deepltranslate\Core\Event\Listener\RenderPageViewLocalizationDropdownEventListener:
72+
tags:
73+
- name: 'event.listener'
74+
identifier: 'deepltranslate-core/translation-dropdown'
75+
event: WebVision\Deepl\Base\Event\ViewHelpers\ModifyInjectVariablesViewHelperEvent
76+
after: 'deepl-base/default-translation'

Resources/Private/Backend/Partials/AdditionalTranslation/DeeplDefault.html

Lines changed: 0 additions & 36 deletions
This file was deleted.

Resources/Private/Backend/Partials/PageLayout/LanguageColumns.html

Lines changed: 0 additions & 145 deletions
This file was deleted.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<html
2+
data-namespace-typo3-fluid="true"
3+
xmlns:deepl="http://typo3.org/ns/WebVision/Deepltranslate/Core/ViewHelpers"
4+
xmlns:f="http://typo3.org/ns/TYPO3Fluid/Fluid/ViewHelpers"
5+
xmlns:core="http://typo3.org/ns/TYPO3/CMS/Core/ViewHelpers"
6+
xmlns:be="http://typo3.org/ns/TYPO3/CMS/Backend/ViewHelpers"
7+
>
8+
<f:if condition="{context.newLanguageOptions}">
9+
<deepl:be.access.deeplTranslateAllowed>
10+
<f:if condition="{deeplLanguages -> f:count()} > 0">
11+
<div class="col row">
12+
<label class="col-sm-4 col">{f:translate(key: 'backend.label', extensionName: 'deepltranslate_core')}</label>
13+
<div class="col col-sm-8">
14+
<select class="form-select" name="createNewLanguage" data-global-event="change" data-action-navigate="$value">
15+
<option><f:translate key="backend.label" extensionName="deepltranslate_core" /></option>
16+
<f:for each="{deeplLanguages}" as="languageName" key="url">
17+
<option value="{url}">{languageName}</option>
18+
</f:for>
19+
</select>
20+
</div>
21+
</div>
22+
</f:if>
23+
</deepl:be.access.deeplTranslateAllowed>
24+
</f:if>
25+
</html>

0 commit comments

Comments
 (0)