66
77use Sinso \Webcomponents \DataProviding \AssertionFailedException ;
88use Sinso \Webcomponents \DataProviding \Traits \RenderComponent ;
9+ use Sinso \Webcomponents \Dto \Events \ComponentFolderIsApplied ;
910use Sinso \Webcomponents \Dto \Events \ComponentWillBeRendered ;
1011use Sinso \Webcomponents \Dto \ComponentRenderingData ;
1112use TYPO3 \CMS \Core \EventDispatcher \EventDispatcher ;
@@ -16,38 +17,26 @@ class WebcomponentContentObject extends AbstractContentObject
1617{
1718 use RenderComponent;
1819
20+ public function __construct (
21+ private readonly EventDispatcher $ eventDispatcher ,
22+ ) {
23+ }
24+
1925 public function render ($ conf = []): string
2026 {
2127 $ componentRenderingData = GeneralUtility::makeInstance (ComponentRenderingData::class);
2228 if ($ this ->cObj ->getCurrentTable () === 'tt_content ' ) {
2329 $ componentRenderingData ->setContentRecord ($ this ->cObj ->data );
2430 }
25- if (isset ($ conf ['additionalInputData. ' ])) {
26- // apply stdWrap to all additionalInputData properties
27- foreach ($ conf ['additionalInputData. ' ] as $ key => $ value ) {
28- if (!str_ends_with ((string ) $ key , '. ' )) {
29- continue ;
30- }
31- $ keyWithoutDot = substr ((string ) $ key , 0 , -1 );
32- $ conf ['additionalInputData. ' ][$ keyWithoutDot ] = $ this ->cObj ->stdWrapValue ($ keyWithoutDot , $ conf ['additionalInputData. ' ]);
33- unset($ conf ['additionalInputData. ' ][$ key ]);
34- }
35- $ componentRenderingData ->setAdditionalInputData ($ conf ['additionalInputData. ' ]);
36- }
31+
32+ $ componentFolder = $ this ->cObj ->stdWrapValue ('componentFolder ' , $ conf );
3733 try {
38- $ componentRenderingData = self ::evaluateComponent ($ componentRenderingData , $ conf ['component ' ] ?? '' , $ this ->cObj );
34+ $ componentRenderingData = $ this ->applyComponentFolder ($ componentRenderingData , $ componentFolder );
35+ $ event = GeneralUtility::makeInstance (ComponentWillBeRendered::class, $ this ->cObj , $ componentRenderingData );
36+ $ this ->eventDispatcher ->dispatch ($ event );
3937 } catch (AssertionFailedException $ e ) {
4038 return $ e ->getRenderingPlaceholder ();
4139 }
42- $ componentRenderingData = $ this ->evaluateTypoScriptConfiguration ($ componentRenderingData , $ conf );
43-
44- $ event = GeneralUtility::makeInstance (ComponentWillBeRendered::class, $ this ->cObj , $ componentRenderingData );
45- $ eventDispatcher = GeneralUtility::makeInstance (EventDispatcher::class);
46- $ eventDispatcher ->dispatch ($ event );
47-
48- if (!$ componentRenderingData ->isRenderable ()) {
49- return '' ;
50- }
5140
5241 // render with tag builder
5342 $ markup = $ this ->renderMarkup ($ componentRenderingData );
@@ -58,19 +47,10 @@ public function render($conf = []): string
5847 return $ markup ;
5948 }
6049
61- private function evaluateTypoScriptConfiguration (ComponentRenderingData $ componentRenderingData , array $ conf ): ComponentRenderingData
50+ private function applyComponentFolder (ComponentRenderingData $ componentRenderingData , string $ componentFolder ): ComponentRenderingData
6251 {
63- if (isset ($ conf ['properties. ' ])) {
64- foreach ($ conf ['properties. ' ] as $ key => $ value ) {
65- if (is_array ($ value )) {
66- continue ;
67- }
68- $ componentRenderingData ->setTagProperty ($ key , $ this ->cObj ->cObjGetSingle ($ value , $ conf ['properties. ' ][$ key . '. ' ]));
69- }
70- }
71- if (($ conf ['tagName ' ] ?? '' ) || ($ conf ['tagName. ' ] ?? [])) {
72- $ componentRenderingData ->setTagName ($ this ->cObj ->stdWrap ($ conf ['tagName ' ] ?? '' , $ conf ['tagName. ' ] ?? []) ?: null );
73- }
52+ $ event = GeneralUtility::makeInstance (ComponentFolderIsApplied::class, $ componentRenderingData , $ this ->cObj , $ componentFolder );
53+ $ this ->eventDispatcher ->dispatch ($ event );
7454 return $ componentRenderingData ;
7555 }
7656
0 commit comments