Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Classes/EventListener/ModifyButtonBarEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Xima\XimaTypo3FrontendEdit\EventListener;

use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Template\Components\{ButtonBar, ModifyButtonBarEvent};
use TYPO3\CMS\Backend\Template\Components\Buttons\InputButton;
use TYPO3\CMS\Core\Attribute\AsEventListener;
Expand Down Expand Up @@ -55,7 +56,8 @@ public function __invoke(ModifyButtonBarEvent $event): void
return;
}

if (!array_key_exists('tx_ximatypo3frontendedit', $GLOBALS['TYPO3_REQUEST']->getQueryParams())) {
$request = $GLOBALS['TYPO3_REQUEST'] ?? null;
if (!$request instanceof ServerRequestInterface || !array_key_exists('tx_ximatypo3frontendedit', $request->getQueryParams())) {
return;
}

Expand Down
6 changes: 4 additions & 2 deletions Classes/EventListener/PageLayoutScrollEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

namespace Xima\XimaTypo3FrontendEdit\EventListener;

use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Routing\Route;
use TYPO3\CMS\Backend\Template\Components\ModifyButtonBarEvent;
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Core\Page\PageRenderer;
Expand All @@ -34,7 +36,7 @@
public function __invoke(ModifyButtonBarEvent $event): void
{
$request = $GLOBALS['TYPO3_REQUEST'] ?? null;
if (null === $request) {
if (!$request instanceof ServerRequestInterface) {
return;
}

Expand All @@ -47,7 +49,7 @@ public function __invoke(ModifyButtonBarEvent $event): void

// Verify we're on the web_layout route
$route = $request->getAttribute('route');
if (null === $route || 'web_layout' !== $route->getOption('_identifier')) {
if (!$route instanceof Route || 'web_layout' !== $route->getOption('_identifier')) {
return;
}

Expand Down
6 changes: 4 additions & 2 deletions Classes/Middleware/ToolRendererMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Psr\Container\{ContainerExceptionInterface, NotFoundExceptionInterface};
use Psr\Http\Message\{ResponseInterface, ServerRequestInterface};
use Psr\Http\Server\{MiddlewareInterface, RequestHandlerInterface};
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Exception;
use TYPO3\CMS\Core\Http\Stream;
use Xima\XimaTypo3FrontendEdit\Service\Authentication\BackendUserService;
Expand Down Expand Up @@ -52,9 +53,10 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
return $response;
}

$backendUser = $GLOBALS['BE_USER'] ?? null;
if (
null === $GLOBALS['BE_USER']
|| !is_array($GLOBALS['BE_USER']->user)
!$backendUser instanceof BackendUserAuthentication
|| !is_array($backendUser->user)
) {
return $response;
}
Expand Down
3 changes: 1 addition & 2 deletions Classes/Repository/ContentElementRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,9 @@ public function __construct(
public function fetchContentElements(
int $pid,
int $languageUid,
bool $includeMultilingualContent = true,
): array {
try {
$queryBuilder = $this->buildContentQuery($languageUid, $includeMultilingualContent);
$queryBuilder = $this->buildContentQuery($languageUid, true);

$queryBuilder->andWhere(
$queryBuilder->expr()->eq(
Expand Down
6 changes: 6 additions & 0 deletions Classes/Service/Menu/AbstractMenuButtonBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Xima\XimaTypo3FrontendEdit\Service\Menu;

use TYPO3\CMS\Core\Localization\LanguageService;
use Xima\XimaTypo3FrontendEdit\Configuration;
use Xima\XimaTypo3FrontendEdit\Enumerations\ButtonType;
use Xima\XimaTypo3FrontendEdit\Service\Ui\{IconService, UrlBuilderService};
Expand Down Expand Up @@ -52,4 +53,9 @@ public function addButton(

$menuButton->appendChild($button, $identifier);
}

protected function getLanguageService(): LanguageService
{
return $GLOBALS['LANG'];
}
}
2 changes: 1 addition & 1 deletion Classes/Service/Menu/ContentElementButtonBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function addInfoSection(
): void {
$this->addButton($menuButton, 'div_info', ButtonType::Divider);

$typeLabel = $GLOBALS['LANG']->sL($contentElementConfig['label'] ?? '') ?: $contentElement['CType'];
$typeLabel = $this->getLanguageService()->sL($contentElementConfig['label'] ?? '') ?: $contentElement['CType'];
$header = isset($contentElement['header']) && '' !== $contentElement['header']
? htmlspecialchars(StringUtility::shortenString((string) $contentElement['header']), \ENT_QUOTES, 'UTF-8')
: '';
Expand Down
8 changes: 7 additions & 1 deletion Classes/Service/Menu/ContentElementMenuGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
use TYPO3\CMS\Core\EventDispatcher\EventDispatcher;
use TYPO3\CMS\Core\Exception;
use TYPO3\CMS\Core\Localization\LanguageService;
use Xima\XimaTypo3FrontendEdit\Event\FrontendEditDropdownModifyEvent;
use Xima\XimaTypo3FrontendEdit\Repository\ContentElementRepository;
use Xima\XimaTypo3FrontendEdit\Service\Authentication\BackendUserService;
Expand Down Expand Up @@ -117,7 +118,7 @@ public function getDropdown(
$event = $this->eventDispatcher->dispatch(new FrontendEditDropdownModifyEvent($contentElement, $menuButton, $returnUrlAnchor));

// Add ctypeLabel and ctypeIcon for frontend display
$ctypeLabel = $GLOBALS['LANG']->sL($contentElementConfig['label'] ?? '');
$ctypeLabel = $this->getLanguageService()->sL($contentElementConfig['label'] ?? '');
$contentElement['ctypeLabel'] = '' !== $ctypeLabel ? $ctypeLabel : $contentElement['CType'];

// Render CType icon as HTML
Expand Down Expand Up @@ -267,4 +268,9 @@ private function resolveContextualUrl(bool $contextualEditingEnabled, int $uid,

return $this->urlBuilderService->buildContextualEditUrl($uid, 'tt_content', $languageUid, $returnUrl);
}

private function getLanguageService(): LanguageService
{
return $GLOBALS['LANG'];
}
}
2 changes: 1 addition & 1 deletion Classes/Service/Menu/PageButtonBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private function getDoktypeLabel(int $doktype): string

foreach ($items as $item) {
if (isset($item['value']) && (int) $item['value'] === $doktype) {
return $GLOBALS['LANG']->sL($item['label'] ?? '') ?: 'Page';
return $this->getLanguageService()->sL($item['label'] ?? '') ?: 'Page';
}
}

Expand Down
8 changes: 5 additions & 3 deletions Classes/Service/Ui/FlashMessageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use JsonException;
use Psr\Log\LoggerInterface;
use Throwable;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Messaging\FlashMessageQueue;
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;

Expand Down Expand Up @@ -48,7 +49,8 @@ public function __construct(
*/
public function collectFromSession(): array
{
if (null === $GLOBALS['BE_USER'] || !is_array($GLOBALS['BE_USER']->user)) {
$backendUser = $GLOBALS['BE_USER'] ?? null;
if (!$backendUser instanceof BackendUserAuthentication || !is_array($backendUser->user)) {
return [];
}

Expand All @@ -63,7 +65,7 @@ public function collectFromSession(): array

foreach ($queues as $queueIdentifier) {
try {
$sessionData = $GLOBALS['BE_USER']->getSessionData($queueIdentifier);
$sessionData = $backendUser->getSessionData($queueIdentifier);

if (!is_array($sessionData) || [] === $sessionData) {
continue;
Expand Down Expand Up @@ -92,7 +94,7 @@ public function collectFromSession(): array
}

// Clear session after processing (malformed messages are discarded)
$GLOBALS['BE_USER']->setAndSaveSessionData($queueIdentifier, null);
$backendUser->setAndSaveSessionData($queueIdentifier, null);
} catch (Throwable $e) {
$this->logger->error('Failed to process flash message queue', [
'queue' => $queueIdentifier,
Expand Down
9 changes: 4 additions & 5 deletions Classes/Service/Ui/ResourceRendererService.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@ public function __construct(
) {}

/**
* @param array<string, mixed> $values
* @param array<array{title: string, message: string, severity: string}> $flashMessages
*
* @throws Exception
*/
public function render(string $template = 'FrontendEdit.html', array $values = [], ?ServerRequestInterface $request = null, array $flashMessages = []): string
public function render(ServerRequestInterface $request, array $flashMessages = []): string
{
$template = 'FrontendEdit.html';

try {
$nonceValue = $this->resolveNonceValue();
$nonceAttribute = '' !== $nonceValue ? ' nonce="'.$nonceValue.'"' : '';
Expand All @@ -68,9 +69,7 @@ public function render(string $template = 'FrontendEdit.html', array $values = [
$this->addStickyToolbarResourcesIfEnabled($resources, $request, $nonceAttribute);
$this->addFlashMessagesConfig($resources, $nonceAttribute, $flashMessages);

$values = [...$values, 'resources' => $resources];

return $this->renderView($template, $values, $request);
return $this->renderView($template, ['resources' => $resources], $request);
} catch (Throwable $exception) {
throw new Exception('Failed to render template "'.$template.'": '.$exception->getMessage(), 1640000001, $exception);
}
Expand Down
16 changes: 8 additions & 8 deletions Classes/Service/Ui/UrlBuilderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,28 +212,28 @@ public function buildDeleteUrl(int $uid, string $table, string $returnUrl): stri
}

/**
* @param array<string, mixed> $parameters
*
* @throws RouteNotFoundException
*/
public function buildRoute(string $route, array $parameters = []): string
public function buildToggleUrl(): string
{
return $this->uriBuilder->buildUriFromRoute($route, $parameters)->__toString();
return $this->buildRoute('ajax_frontendEdit_toggle');
}

/**
* @throws RouteNotFoundException
*/
public function buildToggleUrl(): string
public function buildEditInformationUrl(): string
{
return $this->buildRoute('ajax_frontendEdit_toggle');
return $this->buildRoute('ajax_frontendEdit_editInformation');
}

/**
* @param array<string, mixed> $parameters
*
* @throws RouteNotFoundException
*/
public function buildEditInformationUrl(): string
private function buildRoute(string $route, array $parameters = []): string
{
return $this->buildRoute('ajax_frontendEdit_editInformation');
return $this->uriBuilder->buildUriFromRoute($route, $parameters)->__toString();
}
}
8 changes: 7 additions & 1 deletion Classes/Template/Component/Button.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Xima\XimaTypo3FrontendEdit\Template\Component;

use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Localization\LanguageService;
use Xima\XimaTypo3FrontendEdit\Enumerations\ButtonType;

use function array_key_exists;
Expand Down Expand Up @@ -148,7 +149,7 @@ public function removeChild(string|int $key): void
public function render(): array
{
$result = [
'label' => $GLOBALS['LANG']->sL($this->label),
'label' => $this->getLanguageService()->sL($this->label),
'type' => $this->type->value,
];

Expand All @@ -171,4 +172,9 @@ public function render(): array

return $result;
}

private function getLanguageService(): LanguageService
{
return $GLOBALS['LANG'];
}
}
6 changes: 4 additions & 2 deletions Classes/ViewHelpers/DataViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Xima\XimaTypo3FrontendEdit\ViewHelpers;

use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use Xima\XimaTypo3FrontendEdit\Configuration;

Expand Down Expand Up @@ -70,9 +71,10 @@ public function initializeArguments(): void

public function render(): string
{
$backendUser = $GLOBALS['BE_USER'] ?? null;
if (
null === $GLOBALS['BE_USER']
|| ($GLOBALS['BE_USER']->uc[Configuration::UC_KEY_DISABLED] ?? false)
!$backendUser instanceof BackendUserAuthentication
|| ($backendUser->uc[Configuration::UC_KEY_DISABLED] ?? false)
) {
return '';
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/CGL/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"helmich/typo3-typoscript-lint": "^3.3.0",
"konradmichalik/php-cs-fixer-preset": "^0.1.1",
"konradmichalik/php-doc-block-header-fixer": "^0.3.3",
"konradmichalik/phpstan-typo3-preset": "^0.2",
"konradmichalik/phpstan-typo3-preset": "^0.3",
"move-elevator/composer-translation-validator": "^1.4.0",
"phpstan/phpstan-phpunit": "^1.0 || ^2.0",
"psr/http-message": "^1.0 || ^2.0",
Expand Down
4 changes: 4 additions & 0 deletions Tests/CGL/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@ parameters:
excludePaths:
- ../../.Build (?)

typo3:
requestGetAttributeMapping:
route: 'TYPO3\CMS\Backend\Routing\Route|null'

type_coverage:
constant: 0 # TODO: Set to 100, when PHP 8.3 is minimum requirement
27 changes: 9 additions & 18 deletions Tests/Unit/Service/Menu/ContentElementButtonBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,9 @@ public function addInfoSectionAddsChildrenToMenuButton(): void
$builder = new ContentElementButtonBuilder($this->iconService, $this->urlBuilderService);
$menuButton = new Button('Menu', ButtonType::Menu);

$GLOBALS['LANG'] = new class {
public function sL(string $key): string
{
return 'Translated';
}
};
$languageService = $this->createMock(\TYPO3\CMS\Core\Localization\LanguageService::class);
$languageService->method('sL')->willReturn('Translated');
$GLOBALS['LANG'] = $languageService;

$builder->addInfoSection($menuButton, ['uid' => 1, 'CType' => 'text', 'header' => 'Test'], ['label' => 'Text', 'icon' => 'content-text']);

Expand All @@ -142,12 +139,9 @@ public function addInfoSectionHandlesEmptyHeader(): void
$builder = new ContentElementButtonBuilder($this->iconService, $this->urlBuilderService);
$menuButton = new Button('Menu', ButtonType::Menu);

$GLOBALS['LANG'] = new class {
public function sL(string $key): string
{
return 'Translated';
}
};
$languageService = $this->createMock(\TYPO3\CMS\Core\Localization\LanguageService::class);
$languageService->method('sL')->willReturn('Translated');
$GLOBALS['LANG'] = $languageService;

$builder->addInfoSection($menuButton, ['uid' => 1, 'CType' => 'text', 'header' => ''], ['label' => 'Text']);

Expand All @@ -162,12 +156,9 @@ public function addInfoSectionHandlesMissingHeader(): void
$builder = new ContentElementButtonBuilder($this->iconService, $this->urlBuilderService);
$menuButton = new Button('Menu', ButtonType::Menu);

$GLOBALS['LANG'] = new class {
public function sL(string $key): string
{
return 'Translated';
}
};
$languageService = $this->createMock(\TYPO3\CMS\Core\Localization\LanguageService::class);
$languageService->method('sL')->willReturn('Translated');
$GLOBALS['LANG'] = $languageService;

$builder->addInfoSection($menuButton, ['uid' => 1, 'CType' => 'text'], ['label' => 'Text']);

Expand Down
9 changes: 3 additions & 6 deletions Tests/Unit/Service/Menu/PageButtonBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,9 @@ public function addActionSectionAddsInfoAndHistoryButtons(): void

private function setUpGlobals(): void
{
$GLOBALS['LANG'] = new class {
public function sL(string $key): string
{
return 'Translated';
}
};
$languageService = $this->createMock(\TYPO3\CMS\Core\Localization\LanguageService::class);
$languageService->method('sL')->willReturn('Translated');
$GLOBALS['LANG'] = $languageService;
$GLOBALS['TCA']['pages']['columns']['doktype']['config']['items'] = [
['label' => 'Standard', 'value' => 1],
];
Expand Down
Loading