TYPO3 CMS  TYPO3_8-7
CreatePagesWizardModuleFunctionController.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 
23 
28 {
34  protected $tsConfig = [];
35 
41  protected $pagesTsConfig = [];
42 
48  public function main()
49  {
50  $this->getLanguageService()->includeLLFile('EXT:wizard_crpages/Resources/Private/Language/locallang.xlf');
51  $assigns = [];
52  $assigns['LLPrefix'] = 'LLL:EXT:wizard_crpages/Resources/Private/Language/locallang.xlf:';
53  $this->tsConfig = BackendUtility::getPagesTSconfig($this->pObj->id);
54  $this->pagesTsConfig = isset($this->tsConfig['TCEFORM.']['pages.']) ? $this->tsConfig['TCEFORM.']['pages.'] : [];
55 
56  // Create new pages here?
57  $pageRecord = BackendUtility::getRecord('pages', $this->pObj->id, 'uid', ' AND ' . $this->getBackendUser()->getPagePermsClause(8));
58  $pageRepository = GeneralUtility::makeInstance(PageRepository::class);
59  $menuItems = $pageRepository->getMenu($this->pObj->id, '*', 'sorting', '', false);
60  if (is_array($pageRecord)) {
61  $data = GeneralUtility::_GP('data');
62  if (is_array($data['pages'])) {
63  if (GeneralUtility::_GP('createInListEnd')) {
64  $endI = end($menuItems);
65  $thePid = -(int)$endI['uid'];
66  if (!$thePid) {
67  $thePid = $this->pObj->id;
68  }
69  } else {
70  $thePid = $this->pObj->id;
71  }
72  $firstRecord = true;
73  $previousIdentifier = '';
74  foreach ($data['pages'] as $identifier => $dat) {
75  if (!trim($dat['title'])) {
76  unset($data['pages'][$identifier]);
77  } else {
78  $data['pages'][$identifier]['hidden'] = GeneralUtility::_GP('hidePages') ? 1 : 0;
79  $data['pages'][$identifier]['nav_hide'] = GeneralUtility::_GP('hidePagesInMenus') ? 1 : 0;
80  if ($firstRecord) {
81  $firstRecord = false;
82  $data['pages'][$identifier]['pid'] = $thePid;
83  } else {
84  $data['pages'][$identifier]['pid'] = '-' . $previousIdentifier;
85  }
86  $previousIdentifier = $identifier;
87  }
88  }
89  if (!empty($data['pages'])) {
90  reset($data);
91  $dataHandler = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
92  // set default TCA values specific for the user
93  $TCAdefaultOverride = $this->getBackendUser()->getTSConfigProp('TCAdefaults');
94  if (is_array($TCAdefaultOverride)) {
95  $dataHandler->setDefaultsFromUserTS($TCAdefaultOverride);
96  }
97  $dataHandler->start($data, []);
98  $dataHandler->process_datamap();
99  BackendUtility::setUpdateSignal('updatePageTree');
100  $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, '', $this->getLanguageService()->getLL('wiz_newPages_create'));
101  } else {
102  $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, '', $this->getLanguageService()->getLL('wiz_newPages_noCreate'), FlashMessage::ERROR);
103  }
105  $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
107  $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
108  $defaultFlashMessageQueue->enqueue($flashMessage);
109  // Display result:
110  $menuItems = $pageRepository->getMenu($this->pObj->id, '*', 'sorting', '', false);
111  $pageLines = [];
112  foreach ($menuItems as $record) {
113  BackendUtility::workspaceOL('pages', $record);
114  if (is_array($record)) {
115  $line = [];
116  $line['titleAttribute'] = BackendUtility::titleAttribForPages($record, '', false);
117  $line['title'] = GeneralUtility::fixed_lgd_cs($record['title'], $this->getBackendUser()->uc['titleLen']);
118  $line['record'] = $record;
119  $pageLines[] = $line;
120  }
121  }
122  $assigns['pages'] = $pageLines;
123  } else {
124  // Display create form
125  $assigns['typeSelect'] = $this->getTypeSelectData();
126  }
127  } else {
128  $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, '', $this->getLanguageService()->getLL('wiz_newPages_errorMsg1'), FlashMessage::ERROR);
130  $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
132  $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
133  $defaultFlashMessageQueue->enqueue($flashMessage);
134  }
135  // CSH
136  $assigns['cshItem'] = BackendUtility::cshItem('_MOD_web_func', 'tx_wizardcrpages');
137 
138  // Rendering of the output via fluid
139  $view = GeneralUtility::makeInstance(StandaloneView::class);
140  $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
141  'EXT:wizard_crpages/Resources/Private/Templates/CreatePagesWizard.html'
142  ));
143  $view->assignMultiple($assigns);
144  $out = $view->render();
145 
146  return $out;
147  }
148 
154  protected function getTypeSelectData()
155  {
156  // find all available doktypes for the current user
157  $types = $GLOBALS['PAGES_TYPES'];
158  unset($types['default']);
159  $types = array_keys($types);
161  $types[] = PageRepository::DOKTYPE_LINK;
165 
166  if (!$this->getBackendUser()->isAdmin() && isset($this->getBackendUser()->groupData['pagetypes_select'])) {
167  $types = GeneralUtility::trimExplode(',', $this->getBackendUser()->groupData['pagetypes_select'], true);
168  }
169  $removeItems = isset($this->pagesTsConfig['doktype.']['removeItems']) ? GeneralUtility::trimExplode(',', $this->pagesTsConfig['doktype.']['removeItems'], true) : [];
170  $allowedDoktypes = array_diff($types, $removeItems);
171 
172  // fetch all doktypes in the TCA
173  $availableDoktypes = $GLOBALS['TCA']['pages']['columns']['doktype']['config']['items'];
174 
175  // sort by group and allowedDoktypes
176  $groupedData = [];
177  $groupLabel = '';
178  foreach ($availableDoktypes as $doktypeData) {
179  // if it is a group, save the group label for the children underneath
180  if ($doktypeData[1] === '--div--') {
181  $groupLabel = $doktypeData[0];
182  } else {
183  if (in_array($doktypeData[1], $allowedDoktypes)) {
184  $groupedData[$groupLabel][] = $doktypeData;
185  }
186  }
187  }
188 
189  return $groupedData;
190  }
191 
197  protected function getLanguageService()
198  {
199  return $GLOBALS['LANG'];
200  }
201 
207  protected function getBackendUser()
208  {
209  return $GLOBALS['BE_USER'];
210  }
211 }
static getPagesTSconfig($id, $rootLine=null, $returnPartArray=false)
static getFileAbsFileName($filename, $_=null, $_2=null)
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
static workspaceOL($table, &$row, $wsid=-99, $unsetMovePointers=false)
static makeInstance($className,... $constructorArguments)
static setUpdateSignal($set='', $params='')
static cshItem($table, $field, $_='', $wrap='')
static fixed_lgd_cs($string, $chars, $appendString='...')
static titleAttribForPages($row, $perms_clause='', $includeAttrib=true)
static getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']