TYPO3 CMS  TYPO3_7-6
ModuleTemplate.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 
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 
93  protected $uiBlock = false;
94 
100  protected $templateRootPaths = ['EXT:backend/Resources/Private/Templates'];
101 
107  protected $partialRootPaths = ['EXT:backend/Resources/Private/Partials'];
108 
114  protected $layoutRootPaths = ['EXT:backend/Resources/Private/Layouts'];
115 
121  protected $templateFile = 'Module.html';
122 
128  protected $view;
129 
135  protected $content = '';
136 
142  protected $sectionFlag = 0;
143 
149  protected $iconFactory;
150 
156  protected $moduleId = '';
157 
163  protected $moduleName = '';
164 
170  protected $title = '';
171 
177  protected $bodyTag = '<body>';
178 
185 
191  public function getBodyTag()
192  {
193  return $this->bodyTag;
194  }
195 
201  public function setBodyTag($bodyTag)
202  {
203  $this->bodyTag = $bodyTag;
204  }
205 
211  public function getView()
212  {
213  return $this->view;
214  }
215 
222  public function setContent($content)
223  {
224  $this->view->assign('content', $content);
225  }
226 
232  public function setTitle($title)
233  {
234  $this->title = $title;
235  }
236 
242  public function getIconFactory()
243  {
244  return $this->iconFactory;
245  }
246 
253  public function __construct()
254  {
255  $this->view = GeneralUtility::makeInstance(StandaloneView::class);
256  $this->view->setPartialRootPaths($this->partialRootPaths);
257  $this->view->setTemplateRootPaths($this->templateRootPaths);
258  $this->view->setLayoutRootPaths($this->layoutRootPaths);
259  $this->view->setTemplate($this->templateFile);
260  $this->pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
261  $this->docHeaderComponent = GeneralUtility::makeInstance(DocHeaderComponent::class);
262  $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
263  }
264 
270  protected function loadJavaScripts()
271  {
272  $this->pageRenderer->loadJquery();
273  $this->pageRenderer->loadRequireJsModule('bootstrap');
274  $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/ContextHelp');
275  $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/DocumentHeader');
276  $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/SplitButtons');
277  }
278 
284  protected function loadStylesheets()
285  {
286  if ($GLOBALS['TBE_STYLES']['stylesheet']) {
287  $this->pageRenderer->addCssFile($GLOBALS['TBE_STYLES']['stylesheet']);
288  }
289  if ($GLOBALS['TBE_STYLES']['stylesheet2']) {
290  $this->pageRenderer->addCssFile($GLOBALS['TBE_STYLES']['stylesheet2']);
291  }
292  }
293 
299  protected function setupPage()
300  {
301  // Yes, hardcoded on purpose
302  $this->pageRenderer->setXmlPrologAndDocType('<!DOCTYPE html>');
303  $this->pageRenderer->setCharSet('utf-8');
304  $this->pageRenderer->setLanguage($GLOBALS['LANG']->lang);
305  $this->pageRenderer->addMetaTag('<meta name="viewport" content="width=device-width, initial-scale=1">');
306  }
307 
313  protected function setJavaScriptCodeArray()
314  {
315  foreach ($this->javascriptCodeArray as $name => $code) {
316  $this->pageRenderer->addJsInlineCode($name, $code, false);
317  }
318  }
319 
328  public function addJavaScriptCode($name = '', $code = '')
329  {
330  $this->javascriptCodeArray[$name] = $code;
331  }
332 
338  public function getDocHeaderComponent()
339  {
341  }
342 
348  public function renderContent()
349  {
350  $this->setupPage();
351  $this->pageRenderer->setTitle($this->title);
352  $this->loadJavaScripts();
353  $this->setJavaScriptCodeArray();
354  $this->loadStylesheets();
355 
356  $this->view->assign('docHeader', $this->docHeaderComponent->docHeaderContent());
357  if ($this->moduleId) {
358  $this->view->assign('moduleId', $this->moduleId);
359  }
360  if ($this->moduleName) {
361  $this->view->assign('moduleName', $this->moduleName);
362  }
363  $this->view->assign('uiBlock', $this->uiBlock);
364  $this->view->assign('flashMessageQueueIdentifier', $this->getFlashMessageQueue()->getIdentifier());
365  $renderedPage = $this->pageRenderer->render(PageRenderer::PART_HEADER);
366  $renderedPage .= $this->bodyTag;
367  $renderedPage .= $this->view->render();
368  $this->pageRenderer->addJsFooterInlineCode('updateSignals', BackendUtility::getUpdateSignalCode());
369  $renderedPage .= $this->pageRenderer->render(PageRenderer::PART_FOOTER);
370 
371  return $renderedPage;
372  }
373 
379  public function getPageRenderer()
380  {
381  return $this->pageRenderer;
382  }
383 
391  public function setForm($formTag = '')
392  {
393  $this->view->assign('formTag', $formTag);
394  }
395 
403  public function setModuleId($moduleId)
404  {
405  $this->moduleId = $moduleId;
407  }
408 
416  public function setModuleName($moduleName)
417  {
418  $this->moduleName = $moduleName;
419  }
420 
426  public function registerModuleMenu($moduleMenuIdentifier)
427  {
428  if (isset($GLOBALS['TBE_MODULES_EXT'][$moduleMenuIdentifier])) {
429  $menuEntries =
430  $GLOBALS['TBE_MODULES_EXT'][$moduleMenuIdentifier]['MOD_MENU']['function'];
431  $menu = $this->getDocHeaderComponent()->getMenuRegistry()->makeMenu()->setIdentifier('MOD_FUNC');
432  foreach ($menuEntries as $menuEntry) {
433  $menuItem = $menu->makeMenuItem()
434  ->setTitle($menuEntry['title'])
435  ->setHref('#');
436  $menu->addMenuItem($menuItem);
437  }
438  $this->docHeaderComponent->getMenuRegistry()->addMenu($menu);
439  }
440  }
441 
459  public function getDynamicTabMenu(array $menuItems, $domId, $defaultTabIndex = 1, $collapsible = false, $wrapContent = true, $storeLastActiveTab = true)
460  {
461  $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Tabs');
462  $templatePathAndFileName = 'EXT:backend/Resources/Private/Templates/DocumentTemplate/' . ($collapsible ? 'Collapse.html' : 'Tabs.html');
463  $view = GeneralUtility::makeInstance(StandaloneView::class);
464  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($templatePathAndFileName));
465  $view->assignMultiple([
466  'id' => 'DTM-' . GeneralUtility::shortMD5($domId),
467  'items' => $menuItems,
468  'defaultTabIndex' => $defaultTabIndex,
469  'wrapContent' => $wrapContent,
470  'storeLastActiveTab' => $storeLastActiveTab,
471  ]);
472  return $view->render();
473  }
474 
475  /*******************************************
476  * THE FOLLOWING METHODS ARE SUBJECT TO BE DEPRECATED / DROPPED!
477  *
478  * These methods have been copied over from DocumentTemplate and enables
479  * core modules to drop the dependency to DocumentTemplate altogether without
480  * rewriting these modules now.
481  * The methods below are marked as internal and will be removed
482  * one-by-one with further refactoring of modules.
483  *
484  * Do not use these methods within own extensions if possible or
485  * be prepared to change this later again.
486  *******************************************/
487 
497  public function loadJavascriptLib($lib)
498  {
499  // @todo: maybe we can remove this one as well
500  $this->pageRenderer->addJsFile($lib);
501  }
502 
526  public function makeShortcutIcon($gvList, $setList, $modName, $motherModName = '', $displayName = '', $classes = 'btn btn-default btn-sm')
527  {
528  $gvList = 'route,' . $gvList;
529  $storeUrl = $this->makeShortcutUrl($gvList, $setList);
530  $pathInfo = parse_url(GeneralUtility::getIndpEnv('REQUEST_URI'));
531  // Fallback for alt_mod. We still pass in the old xMOD... stuff,
532  // but TBE_MODULES only knows about "record_edit".
533  // We still need to pass the xMOD name to createShortcut below,
534  // since this is used for icons.
535  $moduleName = $modName === 'xMOD_alt_doc.php' ? 'record_edit' : $modName;
536  // Add the module identifier automatically if typo3/index.php is used:
537  if (GeneralUtility::_GET('M') !== null && isset($GLOBALS['TBE_MODULES']['_PATHS'][$moduleName])) {
538  $storeUrl = '&M=' . $moduleName . $storeUrl;
539  }
540  if ((int)$motherModName === 1) {
541  $motherModule = 'top.currentModuleLoaded';
542  } elseif ($motherModName) {
543  $motherModule = GeneralUtility::quoteJSvalue($motherModName);
544  } else {
545  $motherModule = '\'\'';
546  }
547  $confirmationText = GeneralUtility::quoteJSvalue(
548  $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.makeBookmark')
549  );
550 
551  $shortcutUrl = $pathInfo['path'] . '?' . $storeUrl;
552  $shortcutExist = BackendUtility::shortcutExists($shortcutUrl);
553 
554  if ($shortcutExist) {
555  return '<a class="active ' . htmlspecialchars($classes) . '" title="">' .
556  $this->iconFactory->getIcon('actions-system-shortcut-active', Icon::SIZE_SMALL)->render() . '</a>';
557  }
558 
559  $url = GeneralUtility::quoteJSvalue(rawurlencode($shortcutUrl));
560  $onClick = 'top.TYPO3.ShortcutMenu.createShortcut(' . GeneralUtility::quoteJSvalue(rawurlencode($modName)) .
561  ', ' . $url . ', ' . $confirmationText . ', ' . $motherModule . ', this, ' . GeneralUtility::quoteJSvalue($displayName) . ');return false;';
562 
563  return '<a href="#" class="' . htmlspecialchars($classes) . '" onclick="' . htmlspecialchars($onClick) . '" title="' .
564  $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.makeBookmark', true) . '">' .
565  $this->iconFactory->getIcon('actions-system-shortcut-new', Icon::SIZE_SMALL)->render() . '</a>';
566  }
567 
580  public function makeShortcutUrl($gvList, $setList)
581  {
582  $getParams = GeneralUtility::_GET();
583  $storeArray = array_merge(
585  ['SET' => GeneralUtility::compileSelectedGetVarsFromArray($setList, (array)$GLOBALS['SOBE']->MOD_SETTINGS)]
586  );
587  return GeneralUtility::implodeArrayForUrl('', $storeArray);
588  }
589 
600  public function getVersionSelector($id, $noAction = false)
601  {
603  && !ExtensionManagementUtility::isLoaded('workspaces')
604  ) {
610  $versionGuiObj = GeneralUtility::makeInstance(VersionView::class);
611  return $versionGuiObj->getVersionSelector($id, $noAction);
612  }
613  return '';
614  }
615 
633  public function section($label, $text, $noStrToUpper = false, $sH = false, $type = 0, $allowHtmlInHeader = false)
634  {
635  $str = '';
636  // Setting header
637  if ($label) {
638  if (!$allowHtmlInHeader) {
639  $label = htmlspecialchars($label);
640  }
641  $str .= $this->sectionHeader($this->icons($type) . $label, $sH, $noStrToUpper ? '' : ' class="uppercase"');
642  }
643  // Setting content
644  $str .= '
645 
646  <!-- Section content -->
647 ' . $text;
648  return $this->sectionBegin() . $str;
649  }
650 
660  public function divider($dist)
661  {
662  $dist = (int)$dist;
663  $str = '
664 
665  <!-- DIVIDER -->
666  <hr style="margin-top: ' . $dist . 'px; margin-bottom: ' . $dist . 'px;" />
667 ';
668  return $this->sectionEnd() . $str;
669  }
670 
682  public function sectionHeader($label, $sH = false, $addAttribute = '')
683  {
684  $tag = $sH ? 'h2' : 'h3';
685  if ($addAttribute && $addAttribute[0] !== ' ') {
686  $addAttribute = ' ' . $addAttribute;
687  }
688  $str = '
689 
690  <!-- Section header -->
691  <' . $tag . $addAttribute . '>' . $label . '</' . $tag . '>
692 ';
693  return $this->sectionBegin() . $str;
694  }
695 
707  public function sectionBegin()
708  {
709  if (!$this->sectionFlag) {
710  $this->sectionFlag = 1;
711  $str = '
712 
713  <!-- ***********************
714  Begin output section.
715  *********************** -->
716  <div>
717 ';
718  return $str;
719  }
720  return '';
721  }
722 
732  public function sectionEnd()
733  {
734  if ($this->sectionFlag) {
735  $this->sectionFlag = 0;
736  return '
737  </div>
738  <!-- *********************
739  End output section.
740  ********************* -->
741 ';
742  }
743  return '';
744  }
745 
751  protected function getBackendUserAuthentication()
752  {
753  return $GLOBALS['BE_USER'];
754  }
755 
761  protected function getLanguageService()
762  {
763  return $GLOBALS['LANG'];
764  }
765 
780  public function icons($type)
781  {
782  $icon = '';
783  switch ($type) {
784  case self::STATUS_ICON_ERROR:
785  $icon = 'status-dialog-error';
786  break;
787  case self::STATUS_ICON_WARNING:
788  $icon = 'status-dialog-warning';
789  break;
790  case self::STATUS_ICON_NOTIFICATION:
791  $icon = 'status-dialog-notification';
792  break;
793  case self::STATUS_ICON_OK:
794  $icon = 'status-dialog-ok';
795  break;
796  default:
797  // Do nothing
798  }
799  if ($icon != '') {
800  return $this->iconFactory->getIcon($icon, Icon::SIZE_SMALL)->render();
801  }
802  return '';
803  }
804 
814  public function redirectUrls($thisLocation = '')
815  {
816  $thisLocation = $thisLocation ? $thisLocation : GeneralUtility::linkThisScript([
817  'CB' => '',
818  'SET' => '',
819  'cmd' => '',
820  'popViewId' => ''
821  ]);
822  $out = '
823  var T3_RETURN_URL = ' . GeneralUtility::quoteJSvalue(str_replace('%20', '', rawurlencode(GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'))))) . ';
824  var T3_THIS_LOCATION = ' . GeneralUtility::quoteJSvalue(str_replace('%20', '', rawurlencode($thisLocation))) . '
825  ';
826  return $out;
827  }
828 
837  public function header($text)
838  {
839  $str = '
840 
841  <!-- MAIN Header in page top -->
842  <h1 class="t3js-title-inlineedit">' . htmlspecialchars($text) . '</h1>
843 ';
844  return $this->sectionEnd() . $str;
845  }
846 
857  public function addFlashMessage($messageBody, $messageTitle = '', $severity = AbstractMessage::OK, $storeInSession = true)
858  {
859  if (!is_string($messageBody)) {
860  throw new \InvalidArgumentException('The message body must be of type string, "' . gettype($messageBody) . '" given.', 1446483133);
861  }
862  /* @var \TYPO3\CMS\Core\Messaging\FlashMessage $flashMessage */
863  $flashMessage = GeneralUtility::makeInstance(
864  \TYPO3\CMS\Core\Messaging\FlashMessage::class,
865  $messageBody,
866  $messageTitle,
867  $severity,
868  $storeInSession
869  );
870  $this->getFlashMessageQueue()->enqueue($flashMessage);
871  }
872 
877  {
878  $this->flashMessageQueue = $flashMessageQueue;
879  }
880 
884  protected function getFlashMessageQueue()
885  {
886  if (!isset($this->flashMessageQueue)) {
888  $service = GeneralUtility::makeInstance(FlashMessageService::class);
889  $this->flashMessageQueue = $service->getMessageQueueByIdentifier();
890  }
892  }
893 
897  public function isUiBlock()
898  {
899  return $this->uiBlock;
900  }
901 
905  public function setUiBlock($uiBlock)
906  {
907  $this->uiBlock = (bool)$uiBlock;
908  }
909 }
static compileSelectedGetVarsFromArray($varList, array $getArray, $GPvarAlt=true)
addFlashMessage($messageBody, $messageTitle='', $severity=AbstractMessage::OK, $storeInSession=true)
static linkThisScript(array $getParams=[])
static implodeArrayForUrl($name, array $theArray, $str='', $skipBlank=false, $rawurlencodeParamName=false)
sectionHeader($label, $sH=false, $addAttribute='')
static getFileAbsFileName($filename, $onlyRelative=true, $relToTYPO3_mainDir=false)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
makeShortcutIcon($gvList, $setList, $modName, $motherModName='', $displayName='', $classes='btn btn-default btn-sm')
getDynamicTabMenu(array $menuItems, $domId, $defaultTabIndex=1, $collapsible=false, $wrapContent=true, $storeLastActiveTab=true)
section($label, $text, $noStrToUpper=false, $sH=false, $type=0, $allowHtmlInHeader=false)