-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[EXPERIMENTAL] Integrate with EXT:content_blocks
WIP: Move the new rendering logic to WEBCOMPONENT_CONTENTBLOCK cObj and restore previous behaviour
- Loading branch information
1 parent
e5e4a20
commit 1a5fd47
Showing
11 changed files
with
200 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sinso\Webcomponents\Dto\Events; | ||
|
||
use Sinso\Webcomponents\Dto\ComponentRenderingData; | ||
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; | ||
|
||
readonly class ComponentFolderIsApplied | ||
{ | ||
public function __construct( | ||
public ComponentRenderingData $componentRenderingData, | ||
public ContentObjectRenderer $contentObjectRenderer, | ||
public string $componentFolder, | ||
) { | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
Classes/EventListener/ComponentFolderIsApplied/AddEntryPointToAssetCollector.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sinso\Webcomponents\EventListener\ComponentFolderIsApplied; | ||
|
||
use Praetorius\ViteAssetCollector\Service\ViteService; | ||
use Sinso\Webcomponents\Dto\Events\ComponentFolderIsApplied; | ||
use TYPO3\CMS\Core\Attribute\AsEventListener; | ||
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; | ||
|
||
#[AsEventListener(identifier: 'webcomponents/addEntryPointToAssetCollector')] | ||
class AddEntryPointToAssetCollector | ||
{ | ||
protected const SUPPORTED_ENTRY_POINT_FILE_NAMES = [ | ||
'entry.ts', | ||
'entry.js', | ||
]; | ||
|
||
public function __construct( | ||
private readonly ViteService $viteService | ||
Check failure on line 21 in Classes/EventListener/ComponentFolderIsApplied/AddEntryPointToAssetCollector.php GitHub Actions / phpstan
Check failure on line 21 in Classes/EventListener/ComponentFolderIsApplied/AddEntryPointToAssetCollector.php GitHub Actions / phpstan
|
||
) { | ||
} | ||
|
||
public function __invoke(ComponentFolderIsApplied $event): void | ||
{ | ||
foreach (self::SUPPORTED_ENTRY_POINT_FILE_NAMES as $fileName) { | ||
$this->findAndAddEntryPoint($event->componentFolder . '/Source/' . $fileName); | ||
} | ||
} | ||
|
||
protected function findAndAddEntryPoint(string $entryPointPath): void | ||
{ | ||
$absoluteEntryPointFile = ExtensionManagementUtility::resolvePackagePath($entryPointPath); | ||
if (!file_exists($absoluteEntryPointFile)) { | ||
return; | ||
} | ||
|
||
$this->viteService->addAssetsFromManifest( | ||
$this->viteService->getDefaultManifestFile(), | ||
$entryPointPath, | ||
); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
Classes/EventListener/ComponentFolderIsApplied/DeriveTagNameFromComponentFolder.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sinso\Webcomponents\EventListener\ComponentFolderIsApplied; | ||
|
||
use Sinso\Webcomponents\Dto\Events\ComponentFolderIsApplied; | ||
use TYPO3\CMS\Core\Attribute\AsEventListener; | ||
|
||
#[AsEventListener(identifier: 'webcomponents/deriveTagNameFromComponentFolder')] | ||
class DeriveTagNameFromComponentFolder | ||
{ | ||
public function __invoke(ComponentFolderIsApplied $event): void | ||
{ | ||
$componentFolderPath = rtrim($event->componentFolder, '/'); | ||
$lastFolderName = basename($componentFolderPath); | ||
$event->componentRenderingData->setTagName($lastFolderName); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
Classes/EventListener/ComponentFolderIsApplied/ExecuteProviderFile.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sinso\Webcomponents\EventListener\ComponentFolderIsApplied; | ||
|
||
use Sinso\Webcomponents\DataProviding\ComponentInterface; | ||
use Sinso\Webcomponents\Dto\Events\ComponentFolderIsApplied; | ||
use TYPO3\CMS\Core\Attribute\AsEventListener; | ||
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; | ||
|
||
#[AsEventListener(identifier: 'webcomponents/executeProviderFile')] | ||
class ExecuteProviderFile | ||
{ | ||
public function __invoke(ComponentFolderIsApplied $event): void | ||
{ | ||
$absoluteComponentFolder = ExtensionManagementUtility::resolvePackagePath($event->componentFolder); | ||
$providerFile = $absoluteComponentFolder . '/Source/provide.php'; | ||
if (!file_exists($providerFile)) { | ||
return; | ||
} | ||
|
||
$class = require $providerFile; | ||
$provider = new $class(); | ||
if (!$provider instanceof ComponentInterface) { | ||
throw new \Exception('Provider must implement ComponentInterface', 1722526311); | ||
} | ||
$provider->setContentObjectRenderer($event->contentObjectRenderer); | ||
|
||
$provider->provide($event->componentRenderingData); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sinso\Webcomponents; | ||
|
||
use Psr\Container\ContainerInterface; | ||
use TYPO3\CMS\ContentBlocks\Definition\ContentType\ContentType; | ||
use TYPO3\CMS\ContentBlocks\Definition\TableDefinitionCollection; | ||
use TYPO3\CMS\ContentBlocks\Registry\ContentBlockRegistry; | ||
use TYPO3\CMS\Core\Package\AbstractServiceProvider; | ||
|
||
class ServiceProvider extends AbstractServiceProvider | ||
{ | ||
|
||
protected static function getPackagePath(): string | ||
{ | ||
return __DIR__ . '/../'; | ||
} | ||
|
||
protected static function getPackageName(): string | ||
{ | ||
return 'sinso/webcomponents'; | ||
} | ||
|
||
public function getFactories(): array | ||
{ | ||
return []; | ||
} | ||
|
||
public function getExtensions(): array | ||
{ | ||
return [ | ||
'content-blocks.typoscript' => static::overwriteContentBlocksTypoScript(...), | ||
] + parent::getExtensions(); | ||
} | ||
|
||
public static function overwriteContentBlocksTypoScript(ContainerInterface $container, \ArrayObject $typoScriptArrayObject): \ArrayObject | ||
{ | ||
$contentBlockRegistry = $container->get(ContentBlockRegistry::class); | ||
$tableDefinitionCollection = $container->get(TableDefinitionCollection::class); | ||
foreach ($tableDefinitionCollection as $tableDefinition) { | ||
foreach ($tableDefinition->getContentTypeDefinitionCollection() ?? [] as $typeDefinition) { | ||
if ($tableDefinition->getContentType() !== ContentType::CONTENT_ELEMENT) { | ||
continue; | ||
} | ||
$contentBlockExtPath = $contentBlockRegistry->getContentBlockExtPath($typeDefinition->getName()); | ||
$typoScript = <<<HEREDOC | ||
tt_content.{$typeDefinition->getTypeName()} > | ||
tt_content.{$typeDefinition->getTypeName()} = WEBCOMPONENT | ||
tt_content.{$typeDefinition->getTypeName()}.componentFolder = $contentBlockExtPath | ||
HEREDOC; | ||
$typoScriptArrayObject->append($typoScript); | ||
} | ||
} | ||
|
||
return $typoScriptArrayObject; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters