TYPO3 CMS  TYPO3_7-6
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 
25 
30 {
36  protected $tsConfig = [];
37 
43  protected $pagesTsConfig = [];
44 
48  protected $typeSelectHtml = '';
49 
53  protected $iconFactory;
54 
60  public function main()
61  {
62  $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
63  $this->getLanguageService()->includeLLFile('EXT:wizard_crpages/Resources/Private/Language/locallang.xlf');
64  $theCode = '';
65  $this->tsConfig = BackendUtility::getPagesTSconfig($this->pObj->id);
66  $this->pagesTsConfig = isset($this->tsConfig['TCEFORM.']['pages.']) ? $this->tsConfig['TCEFORM.']['pages.'] : [];
67 
68  // Create new pages here?
69  $pageRecord = BackendUtility::getRecord('pages', $this->pObj->id, 'uid', ' AND ' . $this->getBackendUser()->getPagePermsClause(8));
70  $pageRepository = GeneralUtility::makeInstance(PageRepository::class);
71  $menuItems = $pageRepository->getMenu($this->pObj->id, '*', 'sorting', '', false);
72  if (is_array($pageRecord)) {
73  $data = GeneralUtility::_GP('data');
74  if (is_array($data['pages'])) {
75  if (GeneralUtility::_GP('createInListEnd')) {
76  $endI = end($menuItems);
77  $thePid = -(int)$endI['uid'];
78  if (!$thePid) {
79  $thePid = $this->pObj->id;
80  }
81  } else {
82  $thePid = $this->pObj->id;
83  }
84  $firstRecord = true;
85  $previousIdentifier = '';
86  foreach ($data['pages'] as $identifier => $dat) {
87  if (!trim($dat['title'])) {
88  unset($data['pages'][$identifier]);
89  } else {
90  $data['pages'][$identifier]['hidden'] = GeneralUtility::_GP('hidePages') ? 1 : 0;
91  $data['pages'][$identifier]['nav_hide'] = GeneralUtility::_GP('hidePagesInMenus') ? 1 : 0;
92  if ($firstRecord) {
93  $firstRecord = false;
94  $data['pages'][$identifier]['pid'] = $thePid;
95  } else {
96  $data['pages'][$identifier]['pid'] = '-' . $previousIdentifier;
97  }
98  $previousIdentifier = $identifier;
99  }
100  }
101  if (!empty($data['pages'])) {
102  reset($data);
103  $dataHandler = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
104  $dataHandler->stripslashes_values = 0;
105  // set default TCA values specific for the user
106  $TCAdefaultOverride = $this->getBackendUser()->getTSConfigProp('TCAdefaults');
107  if (is_array($TCAdefaultOverride)) {
108  $dataHandler->setDefaultsFromUserTS($TCAdefaultOverride);
109  }
110  $dataHandler->start($data, []);
111  $dataHandler->process_datamap();
112  BackendUtility::setUpdateSignal('updatePageTree');
113  $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, '', $this->getLanguageService()->getLL('wiz_newPages_create'));
114  } else {
115  $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, '', $this->getLanguageService()->getLL('wiz_newPages_noCreate'), FlashMessage::ERROR);
116  }
118  $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
120  $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
121  $defaultFlashMessageQueue->enqueue($flashMessage);
122  // Display result:
123  $menuItems = $pageRepository->getMenu($this->pObj->id, '*', 'sorting', '', false);
124  $lines = [];
125  foreach ($menuItems as $record) {
126  BackendUtility::workspaceOL('pages', $record);
127  if (is_array($record)) {
128  $lines[] = '<span class="text-nowrap" title="' . BackendUtility::titleAttribForPages($record, '', false) . '">' . $this->iconFactory->getIconForRecord('pages', $record, Icon::SIZE_SMALL)->render() . htmlspecialchars(GeneralUtility::fixed_lgd_cs($record['title'], $this->getBackendUser()->uc['titleLen'])) . '</span>';
129  }
130  }
131  $theCode .= '<div class="form-group"><h4>' . $this->getLanguageService()->getLL('wiz_newPages_currentMenu') . '</h4>' . implode('<br />', $lines) . '</div>';
132  } else {
133  // Display create form
134  $this->typeSelectHtml = $this->getTypeSelectHtml();
135  $tableData = [];
136  for ($a = 0; $a < 5; $a++) {
137  $tableData[] = $this->getFormLine($a);
138  }
139  $theCode .= '
140  <h4>' . $this->getLanguageService()->getLL('wiz_newPages') . ':</h4>
141  <div class="form-group t3js-wizardcrpages-container">
142  ' . implode(LF, $tableData) . '
143  </div>
144  <div class="form-group">
145  <input class="btn btn-default t3js-wizardcrpages-createnewfields" type="button" value="' . $this->getLanguageService()->getLL('wiz_newPages_addMoreLines') . '" />
146  </div>
147  <div class="form-group">
148  <div class="checkbox">
149  <label for="createInListEnd">
150  <input type="checkbox" name="createInListEnd" id="createInListEnd" value="1" />
151  ' . $this->getLanguageService()->getLL('wiz_newPages_listEnd') . '
152  </label>
153  </div>
154  <div class="checkbox">
155  <label for="hidePages">
156  <input type="checkbox" name="hidePages" id="hidePages" value="1" />
157  ' . $this->getLanguageService()->getLL('wiz_newPages_hidePages') . '
158  </label>
159  </div>
160  <div class="checkbox">
161  <label for="hidePagesInMenus">
162  <input type="checkbox" name="hidePagesInMenus" id="hidePagesInMenus" value="1" />
163  ' . $this->getLanguageService()->getLL('wiz_newPages_hidePagesInMenus') . '
164  </label>
165  </div>
166  </div>
167  <div class="form-group">
168  <input class="btn btn-default" type="submit" name="create" value="' . $this->getLanguageService()->getLL('wiz_newPages_lCreate') . '" />
169  <input class="btn btn-default" type="reset" value="' . $this->getLanguageService()->getLL('wiz_newPages_lReset') . '" />
170  </div>';
171 
172  $this->getPageRenderer()->loadJquery();
173  $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/WizardCrpages/WizardCreatePages');
174  // Add inline code
175  $inlineJavaScriptCode = 'var tpl = "' . addslashes(str_replace([LF, TAB], ['', ''], $this->getFormLine('#'))) . '", i, line, div, bg, label;';
176  $this->getPageRenderer()->addJsInlineCode('wizard_crpages', $inlineJavaScriptCode);
177  }
178  } else {
179  $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, '', $this->getLanguageService()->getLL('wiz_newPages_errorMsg1'), FlashMessage::ERROR);
181  $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
183  $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
184  $defaultFlashMessageQueue->enqueue($flashMessage);
185  }
186  // CSH
187  $theCode .= BackendUtility::cshItem('_MOD_web_func', 'tx_wizardcrpages', null, '<span class="btn btn-default btn-sm">|</span>');
188  $out = $this->pObj->doc->header($this->getLanguageService()->getLL('wiz_crMany'));
189  $out .= '<div>' . $theCode . '</div>';
190  return $out;
191  }
192 
199  protected function getFormLine($index)
200  {
201  if (is_numeric($index)) {
202  $label = $index + 1;
203  } else {
204  // used as template for JavaScript
205  $index = '{0}';
206  $label = '{1}';
207  }
208  $content = '' .
209  '<div class="form-section" id="form-line-' . $index . '">' .
210  '<div class="row">' .
211  '<div class="form-group col-sm-6">' .
212  '<label for="page_new_' . $index . '">' .
213  $this->getLanguageService()->getLL('wiz_newPages_page') . ' ' . $label . ':' .
214  '</label>' .
215  '<div class="form-control-wrap">' .
216  '<input class="form-control" type="text" id="page_new_' . $index . '" name="data[pages][NEW' . $index . '][title]" />' .
217  '</div>' .
218  '</div>' .
219  '<div class="form-group col-sm-6">' .
220  '<label>' .
221  $this->getLanguageService()->sL('LLL:EXT:lang/locallang_general.xlf:LGL.type') .
222  '</label>' .
223  '<div class="form-control-wrap">' .
224  '<div class="input-group">' .
225  '<div id="page_new_icon_' . $index . '" class="input-group-addon input-group-icon">' .
226  $this->iconFactory->getIconForRecord('pages', [], Icon::SIZE_SMALL)->render() .
227  '</div>' .
228  '<select class="form-control form-control-adapt t3js-wizardcrpages-select-doktype" name="data[pages][NEW' . $index . '][doktype]" data-target="#page_new_icon_' . $index . '">' .
229  $this->typeSelectHtml .
230  '</select>' .
231  '</div>' .
232  '</div>' .
233  '</div>' .
234  '</div>' .
235  '</div>';
236  return $content;
237  }
238 
244  protected function getTypeSelectHtml()
245  {
246  $content = '';
247 
248  // find all available doktypes for the current user
249  $types = $GLOBALS['PAGES_TYPES'];
250  unset($types['default']);
251  $types = array_keys($types);
253  if (!$this->getBackendUser()->isAdmin() && isset($this->getBackendUser()->groupData['pagetypes_select'])) {
254  $types = GeneralUtility::trimExplode(',', $this->getBackendUser()->groupData['pagetypes_select'], true);
255  }
256  $removeItems = isset($this->pagesTsConfig['doktype.']['removeItems']) ? GeneralUtility::trimExplode(',', $this->pagesTsConfig['doktype.']['removeItems'], true) : [];
257  $allowedDoktypes = array_diff($types, $removeItems);
258 
259  // fetch all doktypes in the TCA
260  $availableDoktypes = $GLOBALS['TCA']['pages']['columns']['doktype']['config']['items'];
261 
262  // sort by group and allowedDoktypes
263  $groupedData = [];
264  foreach ($availableDoktypes as $doktypeData) {
265  // if it is a group, save the group label for the children underneath
266  if ($doktypeData[1] == '--div--') {
267  $groupLabel = $doktypeData[0];
268  } else {
269  if (in_array($doktypeData[1], $allowedDoktypes)) {
270  $groupedData[$groupLabel][] = $doktypeData;
271  }
272  }
273  }
274 
275  // render the HTML
276  foreach ($groupedData as $groupLabel => $items) {
277  $groupContent = '';
278  foreach ($items as $item) {
279  $label = $this->getLanguageService()->sL($item[0], true);
280  $value = $item[1];
281  $icon = !empty($item[2]) ? FormEngineUtility::getIconHtml($item[2], $label, $label) : '';
282  $groupContent .= '<option value="' . htmlspecialchars($value) . '" data-icon="' . htmlspecialchars($icon) . '">' . $label . '</option>';
283  }
284  $groupLabel = $this->getLanguageService()->sL($groupLabel, true);
285  $content .= '<optgroup label="' . $groupLabel . '">' . $groupContent . '</optgroup>';
286  }
287 
288  return $content;
289  }
290 
296  protected function getLanguageService()
297  {
298  return $GLOBALS['LANG'];
299  }
300 
306  protected function getBackendUser()
307  {
308  return $GLOBALS['BE_USER'];
309  }
310 }
static getPagesTSconfig($id, $rootLine=null, $returnPartArray=false)
static getIconHtml($icon, $alt='', $title='')
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
static workspaceOL($table, &$row, $wsid=-99, $unsetMovePointers=false)
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']