TYPO3 CMS  TYPO3_8-7
PageFunctionsController.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
26 
32 {
37  public $pageinfo;
38 
44  protected $moduleTemplate;
45 
51  public $doc;
52 
58  protected $moduleName = 'web_func';
59 
63  protected $iconFactory;
64 
68  protected $view;
69 
73  public function __construct()
74  {
75  $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
76  $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
77  $this->getLanguageService()->includeLLFile('EXT:lang/Resources/Private/Language/locallang_mod_web_func.xlf');
78  $this->MCONF = [
79  'name' => $this->moduleName,
80  ];
81  }
82 
91  public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
92  {
93  $GLOBALS['SOBE'] = $this;
94  $this->init();
95 
96  // Checking for first level external objects
97  $this->checkExtObj();
98 
99  // Checking second level external objects
100  $this->checkSubExtObj();
101  $this->main();
102 
103  $this->moduleTemplate->setContent($this->content);
104 
105  $response->getBody()->write($this->moduleTemplate->renderContent());
106  return $response;
107  }
108 
112  public function main()
113  {
114  // Access check...
115  // The page will show only if there is a valid page and if this page may be viewed by the user
116  $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause);
117  if ($this->pageinfo) {
118  $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($this->pageinfo);
119  }
120  $access = is_array($this->pageinfo);
121  // We keep this here, in case somebody relies on the old doc being here
122  $this->doc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class);
123  // Main
124  if ($this->id && $access) {
125  // JavaScript
126  $this->moduleTemplate->addJavaScriptCode(
127  'WebFuncInLineJS',
128  'if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';'
129  );
130  // Setting up the context sensitive menu:
131  $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu');
132 
133  $this->view = $this->getFluidTemplateObject('func', 'func');
134  $this->view->assign('moduleName', BackendUtility::getModuleUrl('web_func'));
135  $this->view->assign('id', $this->id);
136  $this->view->assign('versionSelector', $this->moduleTemplate->getVersionSelector($this->id, true));
137  $this->view->assign('functionMenuModuleContent', $this->getExtObjContent());
138  // Setting up the buttons and markers for docheader
139  $this->getButtons();
140  $this->generateMenu();
141  $this->content .= $this->view->render();
142  } else {
143  // If no access or if ID == zero
144  $title = $this->getLanguageService()->getLL('title');
145  $message = $this->getLanguageService()->getLL('clickAPage_content');
146  $this->view = $this->getFluidTemplateObject('func', 'func', 'InfoBox');
147  $this->view->assignMultiple([
148  'title' => $title,
149  'message' => $message,
151  ]);
152  $this->content = $this->view->render();
153  // Setting up the buttons and markers for docheader
154  $this->getButtons();
155  }
156  }
157 
163  protected function generateMenu()
164  {
165  $menu = $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
166  $menu->setIdentifier('WebFuncJumpMenu');
167  foreach ($this->MOD_MENU['function'] as $controller => $title) {
168  $item = $menu
169  ->makeMenuItem()
170  ->setHref(
171  BackendUtility::getModuleUrl(
172  $this->moduleName,
173  [
174  'id' => $this->id,
175  'SET' => [
176  'function' => $controller
177  ]
178  ]
179  )
180  )
181  ->setTitle($title);
182  if ($controller === $this->MOD_SETTINGS['function']) {
183  $item->setActive(true);
184  }
185  $menu->addMenuItem($item);
186  }
187  $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu);
188  }
189 
193  protected function getButtons()
194  {
195  $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
196  // CSH
197  $cshButton = $buttonBar->makeHelpButton()
198  ->setModuleName('_MOD_web_func')
199  ->setFieldName('');
200  $buttonBar->addButton($cshButton);
201  if ($this->id && is_array($this->pageinfo)) {
202  // View page
203  $viewButton = $buttonBar->makeLinkButton()
204  ->setOnClick(BackendUtility::viewOnClick($this->pageinfo['uid'], '', BackendUtility::BEgetRootLine($this->pageinfo['uid'])))
205  ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.showPage'))
206  ->setIcon($this->iconFactory->getIcon('actions-document-view', Icon::SIZE_SMALL))
207  ->setHref('#');
208  $buttonBar->addButton($viewButton);
209  // Shortcut
210  $shortcutButton = $buttonBar->makeShortcutButton()
211  ->setModuleName($this->moduleName)
212  ->setGetVariables(['id', 'edit_record', 'pointer', 'new_unique_uid', 'search_field', 'search_levels', 'showLimit'])
213  ->setSetVariables(array_keys($this->MOD_MENU));
214  $buttonBar->addButton($shortcutButton);
215  }
216  }
217 
223  protected function getLanguageService()
224  {
225  return $GLOBALS['LANG'];
226  }
227 
233  protected function getBackendUser()
234  {
235  return $GLOBALS['BE_USER'];
236  }
237 
246  protected function getFluidTemplateObject($extensionName, $controllerExtensionName, $templateName = 'Main')
247  {
249  $view = GeneralUtility::makeInstance(StandaloneView::class);
250  $view->setLayoutRootPaths([GeneralUtility::getFileAbsFileName('EXT:' . $extensionName . '/Resources/Private/Layouts')]);
251  $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:' . $extensionName . '/Resources/Private/Partials')]);
252  $view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:' . $extensionName . '/Resources/Private/Templates')]);
253 
254  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:' . $extensionName . '/Resources/Private/Templates/' . $templateName . '.html'));
255 
256  $view->getRequest()->setControllerExtensionName($controllerExtensionName);
257  return $view;
258  }
259 }
static readPageAccess($id, $perms_clause)
static viewOnClick( $pageUid, $backPath='', $rootLine=null, $anchorSection='', $alternativeUrl='', $additionalGetVars='', $switchFocus=true)
static BEgetRootLine($uid, $clause='', $workspaceOL=false)
static getFileAbsFileName($filename, $_=null, $_2=null)
static makeInstance($className,... $constructorArguments)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
mainAction(ServerRequestInterface $request, ResponseInterface $response)