Skip to content

Commit

Permalink
[TASK] Remove runThroughTemplatesPostProcessing hook
Browse files Browse the repository at this point in the history
Hook call runThroughTemplatesPostProcessing related to the
old TypoScript parser is now removed in the new TypoScript
parser: This hook has been marked as breaking in 12.0
already and was only kept for b/w compat in
typo3/testing-framework, which has been adapted meanwhile.

The substitution event AfterTemplatesHaveBeenDeterminedEvent
is slightly changed to provide the full Request to listeners
instead of just the Site object.

> composer u typo3/testing-framework

Change-Id: I0b46aa50c576782f6853f91105478cd66d0ddcc3
Resolves: #98550
Related: #97816
Releases: main
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/75995
Tested-by: core-ci <typo3@b13.com>
Tested-by: Stefan Bürk <stefan@buerk.tech>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Stefan Bürk <stefan@buerk.tech>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
  • Loading branch information
lolli42 committed Oct 7, 2022
1 parent 365aa64 commit d4ca918
Show file tree
Hide file tree
Showing 19 changed files with 62 additions and 136 deletions.
9 changes: 5 additions & 4 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -17,6 +17,7 @@

namespace TYPO3\CMS\Core\TypoScript\IncludeTree\Event;

use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Site\Entity\SiteInterface;

/**
Expand All @@ -28,7 +29,7 @@ final class AfterTemplatesHaveBeenDeterminedEvent
{
public function __construct(
private readonly array $rootline,
private readonly SiteInterface $site,
private readonly ?ServerRequestInterface $request,
private array $templateRows,
) {
}
Expand All @@ -38,9 +39,17 @@ public function getRootline(): array
return $this->rootline;
}

public function getSite(): SiteInterface
public function getRequest(): ?ServerRequestInterface
{
return $this->site;
return $this->request;
}

/**
* Convenience method to directly retrieve the Site. May be null though!
*/
public function getSite(): ?SiteInterface
{
return $this->request?->getAttribute('site');
}

public function getTemplateRows(): array
Expand Down
Expand Up @@ -19,11 +19,11 @@

use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\Restriction\DefaultRestrictionContainer;
use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction;
use TYPO3\CMS\Core\Site\Entity\SiteInterface;
use TYPO3\CMS\Core\TypoScript\IncludeTree\Event\AfterTemplatesHaveBeenDeterminedEvent;
use TYPO3\CMS\Core\Utility\GeneralUtility;

Expand All @@ -47,14 +47,17 @@ public function __construct(
* To calculate the TS include tree, we have to find sys_template rows attached to all rootline pages.
* When there are multiple active sys_template rows on a page, we pick the one with the lower sorting
* value.
*
* The query implementation below does that with *one* query for all rootline pages at once, not
* one query per page. To handle the capabilities mentioned above, the query is a bit nifty, but
* the implementation should scale nearly O(1) instead of O(n) with the rootline depth.
*
* @param ServerRequestInterface|null $request Nullable since Request is not a hard dependency ond just convenient for the Event
*
* @todo: It's potentially possible to get rid of this method in the frontend by joining sys_template
* into the Page rootline resolving as soon as it uses a CTE.
*/
public function getSysTemplateRowsByRootline(array $rootline, SiteInterface $site): array
public function getSysTemplateRowsByRootline(array $rootline, ?ServerRequestInterface $request = null): array
{
// Site-root node first!
$rootLinePageIds = array_reverse(array_column($rootline, 'uid'));
Expand Down Expand Up @@ -100,7 +103,7 @@ public function getSysTemplateRowsByRootline(array $rootline, SiteInterface $sit
$lastPid = (int)$sysTemplateRow['pid'];
$sysTemplateRows[] = $sysTemplateRow;
}
$event = new AfterTemplatesHaveBeenDeterminedEvent($rootline, $site, $sysTemplateRows);
$event = new AfterTemplatesHaveBeenDeterminedEvent($rootline, $request, $sysTemplateRows);
$this->eventDispatcher->dispatch($event);
return $event->getTemplateRows();
}
Expand All @@ -117,7 +120,7 @@ public function getSysTemplateRowsByRootline(array $rootline, SiteInterface $sit
* one query per page. To handle the capabilities mentioned above, the query is a bit nifty, but
* the implementation should scale nearly O(1) instead of O(n) with the rootline depth.
*/
public function getSysTemplateRowsByRootlineWithUidOverride(array $rootline, SiteInterface $site, int $templateUidOnDeepestRootline): array
public function getSysTemplateRowsByRootlineWithUidOverride(array $rootline, ?ServerRequestInterface $request, int $templateUidOnDeepestRootline): array
{
// Site-root node first!
$rootLinePageIds = array_reverse(array_column($rootline, 'uid'));
Expand Down Expand Up @@ -179,7 +182,7 @@ public function getSysTemplateRowsByRootlineWithUidOverride(array $rootline, Sit
// merged into an early middleware like "SiteResolver" which could join / sub-select
// pages together with sys_template directly, which would be possible if we manage
// to switch away from RootlineUtility usage in SiteResolver by using a CTE instead.
$event = new AfterTemplatesHaveBeenDeterminedEvent($rootline, $site, $sysTemplateRows);
$event = new AfterTemplatesHaveBeenDeterminedEvent($rootline, $request, $sysTemplateRows);
$this->eventDispatcher->dispatch($event);
return $event->getTemplateRows();
}
Expand Down
27 changes: 0 additions & 27 deletions typo3/sysext/core/Classes/TypoScript/IncludeTree/TreeBuilder.php
Expand Up @@ -36,7 +36,6 @@
use TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\RootInclude;
use TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\SiteInclude;
use TYPO3\CMS\Core\TypoScript\IncludeTree\IncludeNode\SysTemplateInclude;
use TYPO3\CMS\Core\TypoScript\TemplateService;
use TYPO3\CMS\Core\TypoScript\Tokenizer\TokenizerInterface;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
Expand Down Expand Up @@ -189,32 +188,6 @@ public function getTreeBySysTemplateRowsAndSite(string $type, array $sysTemplate
$includeTree->addChild($includeNode);
}

// @todo: b/w compat hook hack tailored for testing-framework TyposcriptInstruction runThroughTemplatesPostProcessing hook.
// This hook has already been marked as removed in v12. We should drop it without further notice in v12
// stabilization phase and make TF cope with it, probably by switching to AfterTemplatesHaveBeenDeterminedEvent.
// @deprecated hook runThroughTemplatesPostProcessing, will vanish in v12.
$hookParameters = [];
$templateService = new TemplateService();
foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['Core/TypoScript/TemplateService']['runThroughTemplatesPostProcessing'] ?? [] as $listener) {
GeneralUtility::callUserFunction($listener, $hookParameters, $templateService);
if (!empty($templateService->constants)) {
// @todo: Aehm, we should check $this->type here, shouldn't we?
$node = new DefaultTypoScriptInclude();
$node->setIdentifier('hook-constants');
$node->setName('Hook constants');
$node->setLineStream($this->tokenizer->tokenize(implode(LF, $templateService->constants)));
$includeTree->addChild($node);
}
if (!empty($templateService->config)) {
// @todo: Aehm, we should check $this->type here, shouldn't we?
$node = new DefaultTypoScriptInclude();
$node->setIdentifier('hook-setup');
$node->setName('Hook setup');
$node->setLineStream($this->tokenizer->tokenize(implode(LF, $templateService->config)));
$includeTree->addChild($node);
}
}

if ($this->forceProcessExtensionStatics && !$this->extensionStaticsProcessed) {
// Extbase hack: See property description above.
if ($this->type === 'constants') {
Expand Down
Expand Up @@ -17,7 +17,7 @@ has been removed.

The new event :php:`AfterTemplatesHaveBeenDeterminedEvent` can be used
to manipulate sys_template rows. The event receives the list of resolved
sys_template rows and the :php:`SiteInterface` and allows manipulating the
sys_template rows and the :php:`ServerRequestInterface` and allows manipulating the
sys_template rows array.


Expand Down
Expand Up @@ -51,16 +51,6 @@ abstract class AbstractDataHandlerActionTestCase extends FunctionalTestCase
*/
protected $expectedErrorLogEntries = 0;

protected array $configurationToUseInTestInstance = [
'SC_OPTIONS' => [
'Core/TypoScript/TemplateService' => [
'runThroughTemplatesPostProcessing' => [
'FunctionalTest' => \TYPO3\TestingFramework\Core\Functional\Framework\Frontend\Hook\TypoScriptInstructionModifier::class . '->apply',
],
],
],
];

/**
* @var array
*/
Expand Down
Expand Up @@ -51,16 +51,6 @@ abstract class AbstractDataHandlerActionTestCase extends FunctionalTestCase
*/
protected $expectedErrorLogEntries = 0;

protected array $configurationToUseInTestInstance = [
'SC_OPTIONS' => [
'Core/TypoScript/TemplateService' => [
'runThroughTemplatesPostProcessing' => [
'FunctionalTest' => \TYPO3\TestingFramework\Core\Functional\Framework\Frontend\Hook\TypoScriptInstructionModifier::class . '->apply',
],
],
],
];

/**
* @var array
*/
Expand Down
Expand Up @@ -17,7 +17,6 @@

namespace TYPO3\CMS\Core\Tests\Functional\TypoScript\IncludeTree;

use TYPO3\CMS\Core\Site\Entity\NullSite;
use TYPO3\CMS\Core\TypoScript\IncludeTree\SysTemplateRepository;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;

Expand All @@ -38,9 +37,9 @@ public function singleRootTemplate(): void
];
/** @var SysTemplateRepository $sysTemplateRepository */
$sysTemplateRepository = $this->get(SysTemplateRepository::class);
$result = $sysTemplateRepository->getSysTemplateRowsByRootline($rootline, new NullSite());
$result = $sysTemplateRepository->getSysTemplateRowsByRootline($rootline);
self::assertSame(1, $result[0]['uid']);
$result = $sysTemplateRepository->getSysTemplateRowsByRootlineWithUidOverride($rootline, new NullSite(), 1);
$result = $sysTemplateRepository->getSysTemplateRowsByRootlineWithUidOverride($rootline, null, 1);
self::assertSame(1, $result[0]['uid']);
}

Expand All @@ -64,10 +63,10 @@ public function twoPagesTwoTemplates(): void
];
/** @var SysTemplateRepository $sysTemplateRepository */
$sysTemplateRepository = $this->get(SysTemplateRepository::class);
$result = $sysTemplateRepository->getSysTemplateRowsByRootline($rootline, new NullSite());
$result = $sysTemplateRepository->getSysTemplateRowsByRootline($rootline);
self::assertSame(1, $result[0]['uid']);
self::assertSame(2, $result[1]['uid']);
$result = $sysTemplateRepository->getSysTemplateRowsByRootlineWithUidOverride($rootline, new NullSite(), 2);
$result = $sysTemplateRepository->getSysTemplateRowsByRootlineWithUidOverride($rootline, null, 2);
self::assertSame(1, $result[0]['uid']);
self::assertSame(2, $result[1]['uid']);
}
Expand All @@ -87,9 +86,9 @@ public function twoTemplatesOnPagePrefersTheOneWithLowerSorting(): void
];
/** @var SysTemplateRepository $sysTemplateRepository */
$sysTemplateRepository = $this->get(SysTemplateRepository::class);
$result = $sysTemplateRepository->getSysTemplateRowsByRootline($rootline, new NullSite());
$result = $sysTemplateRepository->getSysTemplateRowsByRootline($rootline);
self::assertSame(1, $result[0]['uid']);
$result = $sysTemplateRepository->getSysTemplateRowsByRootlineWithUidOverride($rootline, new NullSite(), 2);
$result = $sysTemplateRepository->getSysTemplateRowsByRootlineWithUidOverride($rootline, null, 2);
self::assertSame(2, $result[0]['uid']);
}
}
Expand Up @@ -18,7 +18,6 @@
namespace TYPO3\CMS\Core\Tests\Functional\TypoScript\IncludeTree;

use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Site\Entity\NullSite;
use TYPO3\CMS\Core\Site\SiteFinder;
use TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait;
use TYPO3\CMS\Core\TypoScript\AST\Node\RootNode;
Expand Down Expand Up @@ -79,7 +78,7 @@ public function singleRootTemplate(): void
$sysTemplateRepository = $this->get(SysTemplateRepository::class);
/** @var TreeBuilder $treeBuilder */
$treeBuilder = $this->get(TreeBuilder::class);
$includeTree = $treeBuilder->getTreeBySysTemplateRowsAndSite('constants', $sysTemplateRepository->getSysTemplateRowsByRootline($rootline, new NullSite()));
$includeTree = $treeBuilder->getTreeBySysTemplateRowsAndSite('constants', $sysTemplateRepository->getSysTemplateRowsByRootline($rootline));
$ast = $this->getAst($includeTree);
self::assertSame('fooValue', $ast->getChildByName('foo')->getValue());
}
Expand All @@ -102,7 +101,7 @@ public function singleRootTemplateLoadsFromGlobals(): void
$sysTemplateRepository = $this->get(SysTemplateRepository::class);
/** @var TreeBuilder $treeBuilder */
$treeBuilder = $this->get(TreeBuilder::class);
$includeTree = $treeBuilder->getTreeBySysTemplateRowsAndSite('constants', $sysTemplateRepository->getSysTemplateRowsByRootline($rootline, new NullSite()));
$includeTree = $treeBuilder->getTreeBySysTemplateRowsAndSite('constants', $sysTemplateRepository->getSysTemplateRowsByRootline($rootline));
$ast = $this->getAst($includeTree);
self::assertSame('fooValue', $ast->getChildByName('foo')->getValue());
self::assertSame('barValue', $ast->getChildByName('bar')->getValue());
Expand All @@ -129,7 +128,7 @@ public function singleRootTemplateLoadConstantFromSite(): void
$treeBuilder = $this->get(TreeBuilder::class);
$includeTree = $treeBuilder->getTreeBySysTemplateRowsAndSite(
'constants',
$sysTemplateRepository->getSysTemplateRowsByRootline($rootline, new NullSite()),
$sysTemplateRepository->getSysTemplateRowsByRootline($rootline),
$siteFinder->getSiteByPageId(1)
);
$ast = $this->getAst($includeTree);
Expand Down Expand Up @@ -158,7 +157,7 @@ public function twoPagesTwoTemplates(): void
$sysTemplateRepository = $this->get(SysTemplateRepository::class);
/** @var TreeBuilder $treeBuilder */
$treeBuilder = $this->get(TreeBuilder::class);
$includeTree = $treeBuilder->getTreeBySysTemplateRowsAndSite('constants', $sysTemplateRepository->getSysTemplateRowsByRootline($rootline, new NullSite()));
$includeTree = $treeBuilder->getTreeBySysTemplateRowsAndSite('constants', $sysTemplateRepository->getSysTemplateRowsByRootline($rootline));
$ast = $this->getAst($includeTree);
self::assertSame('fooValue', $ast->getChildByName('foo')->getValue());
self::assertSame('barValue', $ast->getChildByName('bar')->getValue());
Expand Down Expand Up @@ -186,7 +185,7 @@ public function twoPagesTwoTemplatesBothClear(): void
$sysTemplateRepository = $this->get(SysTemplateRepository::class);
/** @var TreeBuilder $treeBuilder */
$treeBuilder = $this->get(TreeBuilder::class);
$includeTree = $treeBuilder->getTreeBySysTemplateRowsAndSite('constants', $sysTemplateRepository->getSysTemplateRowsByRootline($rootline, new NullSite()));
$includeTree = $treeBuilder->getTreeBySysTemplateRowsAndSite('constants', $sysTemplateRepository->getSysTemplateRowsByRootline($rootline));
$ast = $this->getAst($includeTree);
self::assertNull($ast->getChildByName('foo'));
self::assertSame('barValue', $ast->getChildByName('bar')->getValue());
Expand All @@ -209,7 +208,7 @@ public function twoTemplatesOnPagePrefersTheOneWithLowerSorting(): void
$sysTemplateRepository = $this->get(SysTemplateRepository::class);
/** @var TreeBuilder $treeBuilder */
$treeBuilder = $this->get(TreeBuilder::class);
$includeTree = $treeBuilder->getTreeBySysTemplateRowsAndSite('constants', $sysTemplateRepository->getSysTemplateRowsByRootline($rootline, new NullSite()));
$includeTree = $treeBuilder->getTreeBySysTemplateRowsAndSite('constants', $sysTemplateRepository->getSysTemplateRowsByRootline($rootline));
$ast = $this->getAst($includeTree);
self::assertSame('fooValue', $ast->getChildByName('foo')->getValue());
self::assertNull($ast->getChildByName('bar'));
Expand All @@ -232,7 +231,7 @@ public function basedOnSimple(): void
$sysTemplateRepository = $this->get(SysTemplateRepository::class);
/** @var TreeBuilder $treeBuilder */
$treeBuilder = $this->get(TreeBuilder::class);
$includeTree = $treeBuilder->getTreeBySysTemplateRowsAndSite('constants', $sysTemplateRepository->getSysTemplateRowsByRootline($rootline, new NullSite()));
$includeTree = $treeBuilder->getTreeBySysTemplateRowsAndSite('constants', $sysTemplateRepository->getSysTemplateRowsByRootline($rootline));
$ast = $this->getAst($includeTree);
self::assertSame('fooValue', $ast->getChildByName('foo')->getValue());
self::assertSame('loadedByBasedOn', $ast->getChildByName('bar')->getValue());
Expand All @@ -255,7 +254,7 @@ public function basedOnAfterIncludeStatic(): void
$sysTemplateRepository = $this->get(SysTemplateRepository::class);
/** @var TreeBuilder $treeBuilder */
$treeBuilder = $this->get(TreeBuilder::class);
$includeTree = $treeBuilder->getTreeBySysTemplateRowsAndSite('constants', $sysTemplateRepository->getSysTemplateRowsByRootline($rootline, new NullSite()));
$includeTree = $treeBuilder->getTreeBySysTemplateRowsAndSite('constants', $sysTemplateRepository->getSysTemplateRowsByRootline($rootline));
$ast = $this->getAst($includeTree);
self::assertSame('fooValue', $ast->getChildByName('foo')->getValue());
self::assertSame('loadedByBasedOn', $ast->getChildByName('bar')->getValue());
Expand All @@ -278,7 +277,7 @@ public function basedOnBeforeIncludeStatic(): void
$sysTemplateRepository = $this->get(SysTemplateRepository::class);
/** @var TreeBuilder $treeBuilder */
$treeBuilder = $this->get(TreeBuilder::class);
$includeTree = $treeBuilder->getTreeBySysTemplateRowsAndSite('constants', $sysTemplateRepository->getSysTemplateRowsByRootline($rootline, new NullSite()));
$includeTree = $treeBuilder->getTreeBySysTemplateRowsAndSite('constants', $sysTemplateRepository->getSysTemplateRowsByRootline($rootline));
$ast = $this->getAst($includeTree);
self::assertSame('fooValue', $ast->getChildByName('foo')->getValue());
self::assertSame('includeStaticTarget', $ast->getChildByName('bar')->getValue());
Expand Down

0 comments on commit d4ca918

Please sign in to comment.