1+ <?php
2+
3+ namespace MarkusTimtner \MtBackend \Backend ;
4+
5+ use TYPO3 \CMS \Backend \Controller \Event \ModifyPageLayoutContentEvent ;
6+
7+ use TYPO3 \CMS \Backend \Controller \PageLayoutController ;
8+ use TYPO3 \CMS \Backend \Utility \BackendUtility ;
9+ use TYPO3 \CMS \Core \Database \ConnectionPool ;
10+ use TYPO3 \CMS \Core \Resource \FileRepository ;
11+ use TYPO3 \CMS \Core \Type \Bitmask \Permission ;
12+ use TYPO3 \CMS \Core \Utility \GeneralUtility ;
13+ use TYPO3 \CMS \Fluid \View \StandaloneView ;
14+
15+
16+ class ModifyPageLayoutContent {
17+
18+ public function __invoke ( ModifyPageLayoutContentEvent $ event ): void {
19+
20+ $ event ->addHeaderContent ( $ this ->renderStuff ( (int ) ( $ event ->getRequest ()
21+ ->getQueryParams ()['id ' ] ?? 0 ) ) );
22+ }
23+ protected function renderStuff (int $ id )
24+ {
25+
26+ $ pageinfo = BackendUtility::readPageAccess ($ id , $ GLOBALS ['BE_USER ' ]->getPagePermsClause (Permission::PAGE_SHOW ));
27+
28+ //load partial paths info from typoscript
29+ $ view = GeneralUtility::makeInstance (StandaloneView::class);
30+ $ view ->setFormat ('html ' );
31+ $ resourcesPath = 'EXT:mt_backend/Resources/ ' ;
32+ $ view ->setTemplatePathAndFilename ($ resourcesPath . 'Private/Templates/PageHook.html ' );
33+
34+ if ($ pageinfo ['media ' ]) {
35+ $ fileRepository = GeneralUtility::makeInstance (FileRepository::class);
36+ $ fileObjects = $ fileRepository ->findByRelation ('pages ' , 'media ' , $ pageinfo ['uid ' ]);
37+ $ view ->assign ('files ' , $ fileObjects );
38+ }
39+
40+ if ($ pageinfo ['categories ' ]) {
41+ $ queryBuilder = GeneralUtility::makeInstance (ConnectionPool::class)->getQueryBuilderForTable ('sys_category ' );
42+ $ query = $ queryBuilder ->select ('sys_category.uid ' , 'sys_category.title ' )->from ('sys_category ' );
43+ $ query ->join (
44+ 'sys_category ' ,
45+ 'sys_category_record_mm ' ,
46+ 'mm ' ,
47+ (string )$ queryBuilder ->expr ()->and (
48+ $ queryBuilder ->expr ()->eq ('mm.uid_local ' , $ queryBuilder ->quoteIdentifier ('sys_category.uid ' )),
49+ $ queryBuilder ->expr ()->in ('mm.uid_foreign ' , $ pageinfo ['uid ' ]),
50+ $ queryBuilder ->expr ()->eq ('mm.tablenames ' , $ queryBuilder ->quote ('pages ' )),
51+ $ queryBuilder ->expr ()->eq ('mm.fieldname ' , $ queryBuilder ->quote ('categories ' ))
52+ )
53+ );
54+ $ categoryObjects = $ query ->executeQuery ()->fetchAllAssociative ();
55+ $ view ->assign ('categories ' , $ categoryObjects );
56+ }
57+
58+ $ view ->assign ('page ' , $ pageinfo );
59+ return $ view ->render ();
60+ }
61+
62+ }
0 commit comments