TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
ModuleTemplate.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Backend\Template;
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 
31 
39 {
45  const STATUS_ICON_ERROR = 3;
46 
53 
60 
66  const STATUS_ICON_OK = -1;
67 
74 
81  protected $javascriptCodeArray = [];
82 
88  protected $pageRenderer;
89 
95  protected $templateRootPaths = ['EXT:backend/Resources/Private/Templates'];
96 
102  protected $partialRootPaths = ['EXT:backend/Resources/Private/Partials'];
103 
109  protected $layoutRootPaths = ['EXT:backend/Resources/Private/Layouts'];
110 
116  protected $templateFile = 'Module.html';
117 
123  protected $view;
124 
130  protected $content = '';
131 
137  protected $iconFactory;
138 
144  protected $moduleId = '';
145 
151  protected $moduleName = '';
152 
158  protected $title = '';
159 
165  protected $bodyTag = '<body>';
166 
173 
179  public function getBodyTag()
180  {
181  return $this->bodyTag;
182  }
183 
189  public function setBodyTag($bodyTag)
190  {
191  $this->bodyTag = $bodyTag;
192  }
193 
199  public function getView()
200  {
201  return $this->view;
202  }
203 
210  public function setContent($content)
211  {
212  $this->view->assign('content', $content);
213  }
214 
220  public function setTitle($title)
221  {
222  $this->title = $title;
223  }
224 
230  public function getIconFactory()
231  {
232  return $this->iconFactory;
233  }
234 
241  public function __construct()
242  {
243  $this->view = GeneralUtility::makeInstance(StandaloneView::class);
244  $this->view->setPartialRootPaths($this->partialRootPaths);
245  $this->view->setTemplateRootPaths($this->templateRootPaths);
246  $this->view->setLayoutRootPaths($this->layoutRootPaths);
247  $this->view->setTemplate($this->templateFile);
248  $this->pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
249  $this->docHeaderComponent = GeneralUtility::makeInstance(DocHeaderComponent::class);
250  $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
251  }
252 
258  protected function loadJavaScripts()
259  {
260  $this->pageRenderer->loadJquery();
261  $this->pageRenderer->loadRequireJsModule('bootstrap');
262  $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/ContextHelp');
263  $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/DocumentHeader');
264  $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/SplitButtons');
265  }
266 
272  protected function loadStylesheets()
273  {
274  if ($GLOBALS['TBE_STYLES']['stylesheet']) {
275  $this->pageRenderer->addCssFile($GLOBALS['TBE_STYLES']['stylesheet']);
276  }
277  if ($GLOBALS['TBE_STYLES']['stylesheet2']) {
278  $this->pageRenderer->addCssFile($GLOBALS['TBE_STYLES']['stylesheet2']);
279  }
280  }
281 
287  protected function setupPage()
288  {
289  // Yes, hardcoded on purpose
290  $this->pageRenderer->setXmlPrologAndDocType('<!DOCTYPE html>');
291  $this->pageRenderer->setCharSet('utf-8');
292  $this->pageRenderer->setLanguage($GLOBALS['LANG']->lang);
293  $this->pageRenderer->addMetaTag('<meta name="viewport" content="width=device-width, initial-scale=1">');
294  }
295 
301  protected function setJavaScriptCodeArray()
302  {
303  foreach ($this->javascriptCodeArray as $name => $code) {
304  $this->pageRenderer->addJsInlineCode($name, $code, false);
305  }
306  }
307 
316  public function addJavaScriptCode($name = '', $code = '')
317  {
318  $this->javascriptCodeArray[$name] = $code;
319  }
320 
326  public function getDocHeaderComponent()
327  {
329  }
330 
336  public function renderContent()
337  {
338  $this->setupPage();
339  $this->pageRenderer->setTitle($this->title);
340  $this->loadJavaScripts();
341  $this->setJavaScriptCodeArray();
342  $this->loadStylesheets();
343 
344  $this->view->assign('docHeader', $this->docHeaderComponent->docHeaderContent());
345  if ($this->moduleId) {
346  $this->view->assign('moduleId', $this->moduleId);
347  }
348  if ($this->moduleName) {
349  $this->view->assign('moduleName', $this->moduleName);
350  }
351  $this->view->assign('flashMessageQueueIdentifier', $this->getFlashMessageQueue()->getIdentifier());
352  $renderedPage = $this->pageRenderer->render(PageRenderer::PART_HEADER);
353  $renderedPage .= $this->bodyTag;
354  $renderedPage .= $this->view->render();
355  $this->pageRenderer->addJsFooterInlineCode('updateSignals', BackendUtility::getUpdateSignalCode());
356  $renderedPage .= $this->pageRenderer->render(PageRenderer::PART_FOOTER);
357 
358  return $renderedPage;
359  }
360 
366  public function getPageRenderer()
367  {
368  return $this->pageRenderer;
369  }
370 
378  public function setForm($formTag = '')
379  {
380  $this->view->assign('formTag', $formTag);
381  }
382 
390  public function setModuleId($moduleId)
391  {
392  $this->moduleId = $moduleId;
394  }
395 
403  public function setModuleName($moduleName)
404  {
405  $this->moduleName = $moduleName;
406  }
407 
413  public function registerModuleMenu($moduleMenuIdentifier)
414  {
415  if (isset($GLOBALS['TBE_MODULES_EXT'][$moduleMenuIdentifier])) {
416  $menuEntries =
417  $GLOBALS['TBE_MODULES_EXT'][$moduleMenuIdentifier]['MOD_MENU']['function'];
418  $menu = $this->getDocHeaderComponent()->getMenuRegistry()->makeMenu()->setIdentifier('MOD_FUNC');
419  foreach ($menuEntries as $menuEntry) {
420  $menuItem = $menu->makeMenuItem()
421  ->setTitle($menuEntry['title'])
422  ->setHref('#');
423  $menu->addMenuItem($menuItem);
424  }
425  $this->docHeaderComponent->getMenuRegistry()->addMenu($menu);
426  }
427  }
428 
446  public function getDynamicTabMenu(array $menuItems, $domId, $defaultTabIndex = 1, $collapsible = false, $wrapContent = true, $storeLastActiveTab = true)
447  {
448  $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Tabs');
449  $templatePath = ExtensionManagementUtility::extPath('backend')
450  . 'Resources/Private/Templates/DocumentTemplate/';
451  $view = GeneralUtility::makeInstance(StandaloneView::class);
452  $view->setTemplatePathAndFilename($templatePath . ($collapsible ? 'Collapse.html' : 'Tabs.html'));
453  $view->setPartialRootPaths([$templatePath . 'Partials']);
454  $view->assignMultiple([
455  'id' => 'DTM-' . GeneralUtility::shortMD5($domId),
456  'items' => $menuItems,
457  'defaultTabIndex' => $defaultTabIndex,
458  'wrapContent' => $wrapContent,
459  'storeLastActiveTab' => $storeLastActiveTab,
460  ]);
461  return $view->render();
462  }
463 
464  /*******************************************
465  * THE FOLLOWING METHODS ARE SUBJECT TO BE DEPRECATED / DROPPED!
466  *
467  * These methods have been copied over from DocumentTemplate and enables
468  * core modules to drop the dependency to DocumentTemplate altogether without
469  * rewriting these modules now.
470  * The methods below are marked as internal and will be removed
471  * one-by-one with further refactoring of modules.
472  *
473  * Do not use these methods within own extensions if possible or
474  * be prepared to change this later again.
475  *******************************************/
476 
486  public function loadJavascriptLib($lib)
487  {
488  // @todo: maybe we can remove this one as well
489  $this->pageRenderer->addJsFile($lib);
490  }
491 
515  public function makeShortcutIcon($gvList, $setList, $modName, $motherModName = '', $displayName = '', $classes = 'btn btn-default btn-sm')
516  {
517  $gvList = 'route,' . $gvList;
518  $storeUrl = $this->makeShortcutUrl($gvList, $setList);
519  $pathInfo = parse_url(GeneralUtility::getIndpEnv('REQUEST_URI'));
520  // Fallback for alt_mod. We still pass in the old xMOD... stuff,
521  // but TBE_MODULES only knows about "record_edit".
522  // We still need to pass the xMOD name to createShortcut below,
523  // since this is used for icons.
524  $moduleName = $modName === 'xMOD_alt_doc.php' ? 'record_edit' : $modName;
525  // Add the module identifier automatically if typo3/index.php is used:
526  if (GeneralUtility::_GET('M') !== null) {
527  $storeUrl = '&M=' . $moduleName . $storeUrl;
528  }
529  if ((int)$motherModName === 1) {
530  $motherModule = 'top.currentModuleLoaded';
531  } elseif ($motherModName) {
532  $motherModule = GeneralUtility::quoteJSvalue($motherModName);
533  } else {
534  $motherModule = '\'\'';
535  }
536  $confirmationText = GeneralUtility::quoteJSvalue(
537  $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.makeBookmark')
538  );
539 
540  $shortcutUrl = $pathInfo['path'] . '?' . $storeUrl;
541  $shortcutExist = BackendUtility::shortcutExists($shortcutUrl);
542 
543  if ($shortcutExist) {
544  return '<a class="active ' . htmlspecialchars($classes) . '" title="">' .
545  $this->iconFactory->getIcon('actions-system-shortcut-active', Icon::SIZE_SMALL)->render() . '</a>';
546  }
547 
548  $url = GeneralUtility::quoteJSvalue(rawurlencode($shortcutUrl));
549  $onClick = 'top.TYPO3.ShortcutMenu.createShortcut(' . GeneralUtility::quoteJSvalue(rawurlencode($modName)) .
550  ', ' . $url . ', ' . $confirmationText . ', ' . $motherModule . ', this, ' . GeneralUtility::quoteJSvalue($displayName) . ');return false;';
551 
552  return '<a href="#" class="' . htmlspecialchars($classes) . '" onclick="' . htmlspecialchars($onClick) . '" title="' .
553  htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.makeBookmark')) . '">' .
554  $this->iconFactory->getIcon('actions-system-shortcut-new', Icon::SIZE_SMALL)->render() . '</a>';
555  }
556 
569  public function makeShortcutUrl($gvList, $setList)
570  {
571  $getParams = GeneralUtility::_GET();
572  $storeArray = array_merge(
574  ['SET' => GeneralUtility::compileSelectedGetVarsFromArray($setList, (array)$GLOBALS['SOBE']->MOD_SETTINGS)]
575  );
576  return GeneralUtility::implodeArrayForUrl('', $storeArray);
577  }
578 
589  public function getVersionSelector($id, $noAction = false)
590  {
592  && !ExtensionManagementUtility::isLoaded('workspaces')
593  ) {
599  $versionGuiObj = GeneralUtility::makeInstance(VersionView::class);
600  return $versionGuiObj->getVersionSelector($id, $noAction);
601  }
602  return '';
603  }
604 
610  protected function getBackendUserAuthentication()
611  {
612  return $GLOBALS['BE_USER'];
613  }
614 
620  protected function getLanguageService()
621  {
622  return $GLOBALS['LANG'];
623  }
624 
639  public function icons($type)
640  {
641  $icon = '';
642  switch ($type) {
643  case self::STATUS_ICON_ERROR:
644  $icon = 'status-dialog-error';
645  break;
646  case self::STATUS_ICON_WARNING:
647  $icon = 'status-dialog-warning';
648  break;
649  case self::STATUS_ICON_NOTIFICATION:
650  $icon = 'status-dialog-notification';
651  break;
652  case self::STATUS_ICON_OK:
653  $icon = 'status-dialog-ok';
654  break;
655  default:
656  // Do nothing
657  }
658  if ($icon != '') {
659  return $this->iconFactory->getIcon($icon, Icon::SIZE_SMALL)->render();
660  }
661  return '';
662  }
663 
673  public function redirectUrls($thisLocation = '')
674  {
675  $thisLocation = $thisLocation ? $thisLocation : GeneralUtility::linkThisScript([
676  'CB' => '',
677  'SET' => '',
678  'cmd' => '',
679  'popViewId' => ''
680  ]);
681  $out = '
682  var T3_RETURN_URL = ' . GeneralUtility::quoteJSvalue(str_replace('%20', '', rawurlencode(GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'))))) . ';
683  var T3_THIS_LOCATION = ' . GeneralUtility::quoteJSvalue(str_replace('%20', '', rawurlencode($thisLocation))) . '
684  ';
685  return $out;
686  }
687 
696  public function header($text)
697  {
698  return '
699 
700  <!-- MAIN Header in page top -->
701  <h1 class="t3js-title-inlineedit">' . htmlspecialchars($text) . '</h1>
702 ';
703  }
704 
715  public function addFlashMessage($messageBody, $messageTitle = '', $severity = AbstractMessage::OK, $storeInSession = true)
716  {
717  if (!is_string($messageBody)) {
718  throw new \InvalidArgumentException('The message body must be of type string, "' . gettype($messageBody) . '" given.', 1446483133);
719  }
720  /* @var \TYPO3\CMS\Core\Messaging\FlashMessage $flashMessage */
721  $flashMessage = GeneralUtility::makeInstance(
722  \TYPO3\CMS\Core\Messaging\FlashMessage::class,
723  $messageBody,
724  $messageTitle,
725  $severity,
726  $storeInSession
727  );
728  $this->getFlashMessageQueue()->enqueue($flashMessage);
729  }
730 
735  {
736  $this->flashMessageQueue = $flashMessageQueue;
737  }
738 
742  protected function getFlashMessageQueue()
743  {
744  if (!isset($this->flashMessageQueue)) {
746  $service = GeneralUtility::makeInstance(FlashMessageService::class);
747  $this->flashMessageQueue = $service->getMessageQueueByIdentifier();
748  }
750  }
751 }
static implodeArrayForUrl($name, array $theArray, $str= '', $skipBlank=false, $rawurlencodeParamName=false)
getDynamicTabMenu(array $menuItems, $domId, $defaultTabIndex=1, $collapsible=false, $wrapContent=true, $storeLastActiveTab=true)
static compileSelectedGetVarsFromArray($varList, array $getArray, $GPvarAlt=true)
static linkThisScript(array $getParams=[])
makeShortcutIcon($gvList, $setList, $modName, $motherModName= '', $displayName= '', $classes= 'btn btn-default btn-sm')
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static makeInstance($className,...$constructorArguments)
addFlashMessage($messageBody, $messageTitle= '', $severity=AbstractMessage::OK, $storeInSession=true)