3131use TYPO3 \CMS \Core \Utility \GeneralUtility ;
3232use TYPO3 \CMS \Core \View \ViewFactoryData ;
3333use TYPO3 \CMS \Core \View \ViewFactoryInterface ;
34+ use TYPO3 \CMS \Core \View \ViewInterface ;
3435use TYPO3 \CMS \Fluid \View \StandaloneView ;
3536
3637class GridRenderer
3738{
38- protected Registry $ tcaRegistry ;
39- protected ContainerFactory $ containerFactory ;
40- protected NewContentUrlBuilder $ newContentUrlBuilder ;
41- protected EventDispatcherInterface $ eventDispatcher ;
42- protected FrontendInterface $ runtimeCache ;
43-
4439 public function __construct (
45- Registry $ tcaRegistry ,
46- ContainerFactory $ containerFactory ,
47- NewContentUrlBuilder $ newContentUrlBuilder ,
48- EventDispatcherInterface $ eventDispatcher ,
49- FrontendInterface $ runtimeCache
40+ protected Registry $ tcaRegistry ,
41+ protected ContainerFactory $ containerFactory ,
42+ protected NewContentUrlBuilder $ newContentUrlBuilder ,
43+ protected EventDispatcherInterface $ eventDispatcher ,
44+ protected ViewFactoryInterface $ viewFactory
5045 ) {
51- $ this ->eventDispatcher = $ eventDispatcher ;
52- $ this ->tcaRegistry = $ tcaRegistry ;
53- $ this ->containerFactory = $ containerFactory ;
54- $ this ->newContentUrlBuilder = $ newContentUrlBuilder ;
55- $ this ->runtimeCache = $ runtimeCache ;
5646 }
5747
5848 public function renderGrid (array $ record , PageLayoutContext $ context ): string
5949 {
60- $ grid = GeneralUtility:: makeInstance (Grid::class, $ context );
50+ $ grid = new Grid ( $ context );
6151 try {
6252 $ container = $ this ->containerFactory ->buildContainer ((int )$ record ['uid ' ]);
6353 } catch (Exception $ e ) {
@@ -66,17 +56,17 @@ public function renderGrid(array $record, PageLayoutContext $context): string
6656 }
6757 $ containerGrid = $ this ->tcaRegistry ->getGrid ($ record ['CType ' ]);
6858 foreach ($ containerGrid as $ cols ) {
69- $ rowObject = GeneralUtility:: makeInstance (GridRow::class, $ context );
59+ $ rowObject = new GridRow ( $ context );
7060 foreach ($ cols as $ col ) {
7161 $ defVals = $ this ->getDefValsForContentDefenderAllowsOnlyOneSpecificContentType ($ record ['CType ' ], (int )$ col ['colPos ' ]);
7262 $ url = $ this ->newContentUrlBuilder ->getNewContentUrlAtTopOfColumn ($ context , $ container , (int )$ col ['colPos ' ], $ defVals );
73- $ columnObject = GeneralUtility:: makeInstance (ContainerGridColumn::class, $ context , $ col , $ container , $ url , $ defVals !== null );
63+ $ columnObject = new ContainerGridColumn ( $ context , $ col , $ container , $ url , $ defVals !== null );
7464 $ rowObject ->addColumn ($ columnObject );
7565 if (isset ($ col ['colPos ' ])) {
7666 $ records = $ container ->getChildrenByColPos ($ col ['colPos ' ]);
7767 foreach ($ records as $ contentRecord ) {
7868 $ url = $ this ->newContentUrlBuilder ->getNewContentUrlAfterChild ($ context , $ container , (int )$ col ['colPos ' ], (int )$ contentRecord ['uid ' ], $ defVals );
79- $ columnItem = GeneralUtility:: makeInstance (ContainerGridColumnItem::class, $ context , $ columnObject , $ contentRecord , $ container , $ url );
69+ $ columnItem = new ContainerGridColumnItem ( $ context , $ columnObject , $ contentRecord , $ container , $ url );
8070 $ columnObject ->addItem ($ columnItem );
8171 }
8272 }
@@ -87,20 +77,12 @@ public function renderGrid(array $record, PageLayoutContext $context): string
8777 $ gridTemplate = $ this ->tcaRegistry ->getGridTemplate ($ record ['CType ' ]);
8878 $ partialRootPaths = $ this ->tcaRegistry ->getGridPartialPaths ($ record ['CType ' ]);
8979 $ layoutRootPaths = $ this ->tcaRegistry ->getGridLayoutPaths ($ record ['CType ' ]);
90- if ((GeneralUtility::makeInstance (Typo3Version::class))->getMajorVersion () <= 13 ) {
91- $ view = GeneralUtility::makeInstance (StandaloneView::class);
92- $ view ->setPartialRootPaths ($ partialRootPaths );
93- $ view ->setLayoutRootPaths ($ layoutRootPaths );
94- $ view ->setTemplatePathAndFilename ($ gridTemplate );
95- } else {
96- $ viewFactory = GeneralUtility::makeInstance (ViewFactoryInterface::class);
97- $ view = $ viewFactory ->create (new ViewFactoryData (
98- null ,
99- $ partialRootPaths ,
100- $ layoutRootPaths ,
101- $ gridTemplate
102- ));
103- }
80+ $ view = $ this ->viewFactory ->create (new ViewFactoryData (
81+ null ,
82+ $ partialRootPaths ,
83+ $ layoutRootPaths ,
84+ $ gridTemplate
85+ ));
10486
10587 $ view ->assign ('hideRestrictedColumns ' , (bool )(BackendUtility::getPagesTSconfig ($ context ->getPageId ())['mod. ' ]['web_layout. ' ]['hideRestrictedCols ' ] ?? false ));
10688 $ view ->assign ('newContentTitle ' , $ this ->getLanguageService ()->sL ('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:newContentElement ' ));
@@ -112,29 +94,17 @@ public function renderGrid(array $record, PageLayoutContext $context): string
11294 $ view ->assign ('gridColumns ' , array_fill (1 , $ grid ->getSpan (), null ));
11395 $ view ->assign ('containerRecord ' , $ record );
11496 $ view ->assign ('context ' , $ context );
115- $ parentGridColumnItem = $ this ->runtimeCache ->get ('tx_container_current_gridColumItem ' );
116- if ((GeneralUtility::makeInstance (Typo3Version::class))->getMajorVersion () <= 13 ) {
117- // cannot be used for v14 / dev-main branch
118- // needs adaption in next major version
119- $ beforeContainerPreviewIsRendered = new BeforeContainerPreviewIsRenderedEvent ($ container , $ view , $ grid , $ parentGridColumnItem );
120- $ this ->eventDispatcher ->dispatch ($ beforeContainerPreviewIsRendered );
121- }
97+ $ beforeContainerPreviewIsRendered = new BeforeContainerPreviewIsRenderedEvent ($ container , $ view , $ grid );
98+ $ this ->eventDispatcher ->dispatch ($ beforeContainerPreviewIsRendered );
12299 $ rendered = $ view ->render ();
123100 return $ rendered ;
124101 }
125102
126103 protected function getDefValsForContentDefenderAllowsOnlyOneSpecificContentType (string $ cType , int $ colPos ): ?array
127104 {
128- $ contentDefefenderConfiguration = $ this ->tcaRegistry ->getContentDefenderConfiguration ($ cType , $ colPos );
129- $ allowedCTypes = GeneralUtility::trimExplode (', ' , $ contentDefefenderConfiguration ['allowed. ' ]['CType ' ] ?? '' , true );
130- $ allowedListTypes = GeneralUtility::trimExplode (', ' , $ contentDefefenderConfiguration ['allowed. ' ]['list_type ' ] ?? '' , true );
105+ $ allowedCTypes = (array )$ this ->tcaRegistry ->getAllowedCTypesInColumn ($ cType , $ colPos );
131106 if (count ($ allowedCTypes ) === 1 ) {
132- if ($ allowedCTypes [0 ] !== 'list ' ) {
133- return ['CType ' => $ allowedCTypes [0 ]];
134- }
135- if (count ($ allowedListTypes ) === 1 ) {
136- return ['CType ' => 'list ' , 'list_type ' => $ allowedListTypes [0 ]];
137- }
107+ return ['CType ' => $ allowedCTypes [0 ]];
138108 }
139109 return null ;
140110 }
0 commit comments