Skip to content

Commit

Permalink
[FEATURE] Facilitate TCA overrides for dynamic Flux content types
Browse files Browse the repository at this point in the history
Due to how TYPO3 treats TCA when compiling, several classes are
blacklisted and are simply not possible to use from within TCA files.
This forces Flux to use an event that triggers *after* TCA has been
compiled, from which to add the various Flux-specific content types
and their TCA.

Because of this, the TCA of Flux-based content types cannot be
modified from within TCA or TCA override files (they are loaded
before the Flux content type exists and once the Flux content
type is created, its TCA overrides the TCA created from files).

Therefore, Flux now implements a custom TCA override file
support where the TCA of dynamic Flux content types can be
overridden or manipulated in the same way standard TCA can.

Placing a file in your extension in Configuration/TCA/Flux, e.g.
Configuration/TCA/Flux/tt_content.php will load those files
after the Flux content types are registered. The files follow the
same approach as a TCA override file (does not return an array,
modifies $GLOBALS['TCA'] directly or uses core's assistance
methods such as ExtensionManagementUtility::addToAllTCAtypes.

Close: #2064
  • Loading branch information
NamelessCoder committed Aug 5, 2023
1 parent fcc9932 commit 9fc8102
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
use FluidTYPO3\Flux\Provider\Provider;
use FluidTYPO3\Flux\Provider\ProviderInterface;
use FluidTYPO3\Flux\Utility\ExtensionNamingUtility;
use Symfony\Component\Finder\Finder;
use TYPO3\CMS\Core\Core\ApplicationContext;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Package\PackageManager;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3Fluid\Fluid\Exception;
Expand All @@ -27,15 +29,18 @@ class SpooledConfigurationApplicator
private ContentTypeBuilder $contentTypeBuilder;
private ContentTypeManager $contentTypeManager;
private RequestBuilder $requestBuilder;
private PackageManager $packageManager;

public function __construct(
ContentTypeBuilder $contentTypeBuilder,
ContentTypeManager $contentTypeManager,
RequestBuilder $requestBuilder
RequestBuilder $requestBuilder,
PackageManager $packageManager
) {
$this->contentTypeBuilder = $contentTypeBuilder;
$this->contentTypeManager = $contentTypeManager;
$this->requestBuilder = $requestBuilder;
$this->packageManager = $packageManager;
}

public function processData(): void
Expand All @@ -55,6 +60,28 @@ public function processData(): void

$this->spoolQueuedContentTypeRegistrations(Core::getQueuedContentTypeRegistrations());
Core::clearQueuedContentTypeRegistrations();

$scopedRequire = static function (string $filename): void {
require $filename;
};

$activePackages = $this->packageManager->getActivePackages();
foreach ($activePackages as $package) {
try {
$finder = Finder::create()
->files()
->sortByName()
->depth(0)
->name('*.php')
->in($package->getPackagePath() . 'Configuration/TCA/Flux');
} catch (\InvalidArgumentException $e) {
// No such directory in this package
continue;
}
foreach ($finder as $fileInfo) {
$scopedRequire($fileInfo->getPathname());
}
}
}

private function spoolQueuedContentTypeTableConfigurations(array $queue): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use FluidTYPO3\Flux\Tests\Fixtures\Classes\DummyConfigurationProvider;
use FluidTYPO3\Flux\Tests\Unit\AbstractTestCase;
use TYPO3\CMS\Core\Core\ApplicationContext;
use TYPO3\CMS\Core\Package\PackageManager;
use TYPO3Fluid\Fluid\Exception;
use TYPO3Fluid\Fluid\View\ViewInterface;

Expand All @@ -32,6 +33,7 @@ class SpooledConfigurationApplicatorTest extends AbstractTestCase
private ContentTypeBuilder $contentTypeBuilder;
private ContentTypeManager $contentTypeManager;
private RequestBuilder $requestBuilder;
private PackageManager $packageManager;

protected function setUp(): void
{
Expand Down Expand Up @@ -81,13 +83,20 @@ protected function setUp(): void

$this->requestBuilder = $this->getMockBuilder(RequestBuilder::class)->disableOriginalConstructor()->getMock();

$this->packageManager = $this->getMockBuilder(PackageManager::class)
->onlyMethods(['getActivePackages'])
->disableOriginalConstructor()
->getMock();
$this->packageManager->method('getActivePackages')->willReturn([]);

$this->subject = $this->getMockBuilder(SpooledConfigurationApplicator::class)
->onlyMethods(['getApplicationContext', 'getContentTypeManager'])
->setConstructorArgs(
[
$this->contentTypeBuilder,
$this->contentTypeManager,
$this->requestBuilder,
$this->packageManager,
]
)
->getMock();
Expand Down

0 comments on commit 9fc8102

Please sign in to comment.