Skip to content

Commit

Permalink
init v12 support (#99)
Browse files Browse the repository at this point in the history
* init v12 support

* Change emconf to drop v11

* [TASK] v12 support
  • Loading branch information
lukaszuznanski authored Feb 22, 2024
1 parent 03b42ee commit b0a405c
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace TYPO3Headless\Typo3Ai\Hook;
namespace TYPO3Headless\Typo3Ai\EventListener;

/*
* This file is part of the Macopedia. package.
Expand All @@ -22,6 +22,8 @@
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3Headless\Typo3Ai\Service\TcaService;
use TYPO3Headless\Typo3Ai\Service\TranslationService;
use TYPO3\CMS\Backend\Template\Components\ModifyButtonBarEvent;


class AddTranslateButton
{
Expand All @@ -32,21 +34,21 @@ public function __construct(
protected TcaService $tcaService
) {}

public function getButtons(array $params, ButtonBar $buttonBar): array
public function __invoke(ModifyButtonBarEvent $event): void
{
$buttons = $params['buttons'];
$buttons = $event->getButtons();

if (isset($GLOBALS['TYPO3_REQUEST']) && $this->translationService->hasCurrentUserCorrectPermisions()) {
$route = $GLOBALS['TYPO3_REQUEST']->getAttribute('route');

if ($route->getPath() !== '/record/edit') {
return $buttons;
return;
}

$editParameters = GeneralUtility::_GET('edit');

if (!is_array($editParameters)) {
return $buttons;
return;
}

$tableName = key($editParameters);
Expand All @@ -59,15 +61,15 @@ public function getButtons(array $params, ButtonBar $buttonBar): array
);

if ($language === 0) {
return $buttons;
return;
}

$actionUri = (string)$this->uriBuilder->buildUriFromRoute(
'translate_ai',
['edit' => $editParameters, 'returnUrl' => (string)$GLOBALS['TYPO3_REQUEST']->getUri()]
);

$translateByAi = $buttonBar->makeLinkButton()
$translateByAi = $event->getButtonBar()->makeLinkButton()
->setShowLabelText(true)
->setHref($actionUri)
->setTitle(
Expand All @@ -77,10 +79,12 @@ public function getButtons(array $params, ButtonBar $buttonBar): array
)
->setIcon($this->iconFactory->getIcon('actions-translate', Icon::SIZE_SMALL));

$buttons[ButtonBar::BUTTON_POSITION_LEFT][20][] = $translateByAi;
}
$buttons[ButtonBar::BUTTON_POSITION_LEFT][20] = [$translateByAi];
$event->setButtons($buttons);

return $buttons;
$test = $event->getButtons();

}
}

/**
Expand Down
5 changes: 4 additions & 1 deletion Configuration/Services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ services:
TYPO3Headless\Typo3Ai\:
resource: '../Classes/*'

TYPO3Headless\Typo3Ai\Hook\AddTranslateButton:
TYPO3Headless\Typo3Ai\EventListener\AddTranslateButton:
public: true
tags:
- name: event.listener
identifier: 'typo3headless-typo3ai/eventlistener/add-translate-button'
2 changes: 1 addition & 1 deletion Resources/Private/Language/locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<source>ChatGPT secret API key</source>
</trans-unit>
<trans-unit id="chatgpt.id" xml:space="preserve">
<source>ChatGPT id</source>
<source>ChatGPT organization id</source>
</trans-unit>
<trans-unit id="translateAi" xml:space="preserve">
<source>Translate by AI</source>
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"require": {
"php": "~8.1.0",
"openai-php/client": "^0.8.1",
"typo3/cms-core": "^11.5"
"typo3/cms-core": "^12.4"
},
"require-dev": {
"ergebnis/composer-normalize": "^2.37.0",
Expand Down
4 changes: 2 additions & 2 deletions ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
'author_email' => '[email protected]',
'author_company' => 'Macopedia Sp. z o.o.',
'category' => 'be',
'version' => '1.1.1',
'version' => '2.0.0',
'constraints' => [
'depends' => [
'typo3' => '11.4.0-11.5.99'
'typo3' => '12.4.0-12.4.99'
],
'conflicts' => [],
'suggests' => [],
Expand Down
12 changes: 0 additions & 12 deletions ext_localconf.php

This file was deleted.

0 comments on commit b0a405c

Please sign in to comment.