TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
PageFunctionsController.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Func\Controller;
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 
17 use Psr\Http\Message\ResponseInterface;
18 use Psr\Http\Message\ServerRequestInterface;
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 
114  public function main()
115  {
116  // Access check...
117  // The page will show only if there is a valid page and if this page may be viewed by the user
118  $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause);
119  if ($this->pageinfo) {
120  $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($this->pageinfo);
121  }
122  $access = is_array($this->pageinfo);
123  // We keep this here, in case somebody relies on the old doc being here
124  $this->doc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class);
125  // Main
126  if ($this->id && $access) {
127  // JavaScript
128  $this->moduleTemplate->addJavaScriptCode(
129  'WebFuncInLineJS',
130  'if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';');
131  // Setting up the context sensitive menu:
132  $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ClickMenu');
133 
134  $this->view = $this->getFluidTemplateObject('func', 'func');
135  $this->view->assign('moduleName', BackendUtility::getModuleUrl('web_func'));
136  $this->view->assign('id', $this->id);
137  $this->view->assign('versionSelector', $this->moduleTemplate->getVersionSelector($this->id, true));
138  $this->view->assign('functionMenuModuleContent', $this->getExtObjContent());
139  // Setting up the buttons and markers for docheader
140  $this->getButtons();
141  $this->generateMenu();
142  $this->content .= $this->view->render();
143  } else {
144  // If no access or if ID == zero
145  $title = $this->getLanguageService()->getLL('title');
146  $message = $this->getLanguageService()->getLL('clickAPage_content');
147  $this->view = $this->getFluidTemplateObject('func', 'func', 'InfoBox');
148  $this->view->assignMultiple([
149  'title' => $title,
150  'message' => $message,
152  ]);
153  $this->content = $this->view->render();
154  // Setting up the buttons and markers for docheader
155  $this->getButtons();
156  }
157  }
158 
164  protected function generateMenu()
165  {
166  $menu = $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
167  $menu->setIdentifier('WebFuncJumpMenu');
168  foreach ($this->MOD_MENU['function'] as $controller => $title) {
169  $item = $menu
170  ->makeMenuItem()
171  ->setHref(
172  BackendUtility::getModuleUrl(
173  $this->moduleName,
174  [
175  'id' => $this->id,
176  'SET' => [
177  'function' => $controller
178  ]
179  ]
180  )
181  )
182  ->setTitle($title);
183  if ($controller === $this->MOD_SETTINGS['function']) {
184  $item->setActive(true);
185  }
186  $menu->addMenuItem($item);
187  }
188  $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu);
189  }
190 
194  protected function getButtons()
195  {
196  $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
197  // CSH
198  $cshButton = $buttonBar->makeHelpButton()
199  ->setModuleName('_MOD_web_func')
200  ->setFieldName('');
201  $buttonBar->addButton($cshButton);
202  if ($this->id && is_array($this->pageinfo)) {
203  // View page
204  $viewButton = $buttonBar->makeLinkButton()
205  ->setOnClick(BackendUtility::viewOnClick($this->pageinfo['uid'], '', BackendUtility::BEgetRootLine($this->pageinfo['uid'])))
206  ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.showPage'))
207  ->setIcon($this->iconFactory->getIcon('actions-document-view', Icon::SIZE_SMALL))
208  ->setHref('#');
209  $buttonBar->addButton($viewButton);
210  // Shortcut
211  $shortcutButton = $buttonBar->makeShortcutButton()
212  ->setModuleName($this->moduleName)
213  ->setGetVariables(['id', 'edit_record', 'pointer', 'new_unique_uid', 'search_field', 'search_levels', 'showLimit'])
214  ->setSetVariables(array_keys($this->MOD_MENU));
215  $buttonBar->addButton($shortcutButton);
216  }
217  }
218 
224  protected function getLanguageService()
225  {
226  return $GLOBALS['LANG'];
227  }
228 
234  protected function getBackendUser()
235  {
236  return $GLOBALS['BE_USER'];
237  }
238 
247  protected function getFluidTemplateObject($extensionName, $controllerExtensionName, $templateName = 'Main')
248  {
250  $view = GeneralUtility::makeInstance(StandaloneView::class);
251  $view->setLayoutRootPaths([GeneralUtility::getFileAbsFileName('EXT:' . $extensionName . '/Resources/Private/Layouts')]);
252  $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:' . $extensionName . '/Resources/Private/Partials')]);
253  $view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:' . $extensionName . '/Resources/Private/Templates')]);
254 
255  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:' . $extensionName . '/Resources/Private/Templates/' . $templateName . '.html'));
256 
257  $view->getRequest()->setControllerExtensionName($controllerExtensionName);
258  return $view;
259  }
260 }
static viewOnClick($pageUid, $backPath= '', $rootLine=null, $anchorSection= '', $alternativeUrl= '', $additionalGetVars= '', $switchFocus=true)
static BEgetRootLine($uid, $clause= '', $workspaceOL=false)
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static makeInstance($className,...$constructorArguments)
static getFileAbsFileName($filename, $_=null, $_2=null)
mainAction(ServerRequestInterface $request, ResponseInterface $response)