MoveElementController.php 12.4 KB
Newer Older
1
2
3
<?php
namespace TYPO3\CMS\Backend\Controller\ContentElement;

4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
8
9
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
10
 *
11
12
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
15
 * The TYPO3 project - inspiring people to share!
 */
16

17
use Psr\Http\Message\ResponseInterface;
18
use Psr\Http\Message\ServerRequestInterface;
19
use TYPO3\CMS\Backend\Template\ModuleTemplate;
20
21
use TYPO3\CMS\Backend\Tree\View\ContentMovingPagePositionMap;
use TYPO3\CMS\Backend\Tree\View\PageMovingPagePositionMap;
Nicole Cordes's avatar
Nicole Cordes committed
22
use TYPO3\CMS\Backend\Utility\BackendUtility;
23
use TYPO3\CMS\Core\Imaging\Icon;
24
use TYPO3\CMS\Core\Type\Bitmask\Permission;
Nicole Cordes's avatar
Nicole Cordes committed
25
use TYPO3\CMS\Core\Utility\GeneralUtility;
26
use TYPO3\CMS\Fluid\View\StandaloneView;
Nicole Cordes's avatar
Nicole Cordes committed
27

28
29
30
/**
 * Script Class for rendering the move-element wizard display
 */
31
class MoveElementController
32
33
34
35
36
{
    /**
     * @var int
     */
    public $sys_language = 0;
37

38
39
40
41
    /**
     * @var int
     */
    public $page_id;
42

43
44
45
46
    /**
     * @var string
     */
    public $table;
47

48
49
50
51
    /**
     * @var string
     */
    public $R_URI;
52

53
54
55
56
    /**
     * @var int
     */
    public $input_moveUid;
57

58
59
60
61
    /**
     * @var int
     */
    public $moveUid;
62

63
64
65
66
    /**
     * @var int
     */
    public $makeCopy;
67

68
69
70
71
72
73
    /**
     * Pages-select clause
     *
     * @var string
     */
    public $perms_clause;
74

75
76
77
78
79
80
    /**
     * Content for module accumulated here.
     *
     * @var string
     */
    public $content;
81

82
83
84
85
86
87
88
    /**
     * ModuleTemplate object
     *
     * @var ModuleTemplate
     */
    protected $moduleTemplate;

89
90
91
92
93
    /**
     * Constructor
     */
    public function __construct()
    {
94
        $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
95
        $this->getLanguageService()->includeLLFile('EXT:lang/Resources/Private/Language/locallang_misc.xlf');
96
97
98
        $GLOBALS['SOBE'] = $this;
        $this->init();
    }
99

100
101
102
103
104
105
106
107
108
109
110
111
112
113
    /**
     * Constructor, initializing internal variables.
     */
    public function init()
    {
        // Setting internal vars:
        $this->sys_language = (int)GeneralUtility::_GP('sys_language');
        $this->page_id = (int)GeneralUtility::_GP('uid');
        $this->table = GeneralUtility::_GP('table');
        $this->R_URI = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
        $this->input_moveUid = GeneralUtility::_GP('moveUid');
        $this->moveUid = $this->input_moveUid ? $this->input_moveUid : $this->page_id;
        $this->makeCopy = GeneralUtility::_GP('makeCopy');
        // Select-pages where clause for read-access:
114
        $this->perms_clause = $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW);
115
    }
116

117
118
119
120
121
122
123
124
125
126
127
    /**
     * Injects the request object for the current request or subrequest
     * As this controller goes only through the main() method, it is rather simple for now
     *
     * @param ServerRequestInterface $request the current request
     * @param ResponseInterface $response
     * @return ResponseInterface the response with the content
     */
    public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
    {
        $this->main();
128

129
130
        $this->moduleTemplate->setContent($this->content);
        $response->getBody()->write($this->moduleTemplate->renderContent());
131
132
        return $response;
    }
133

134
135
136
137
138
139
140
    /**
     * Creating the module output.
     */
    public function main()
    {
        $lang = $this->getLanguageService();
        if ($this->page_id) {
141
            $assigns = [];
142
            $backendUser = $this->getBackendUser();
143
            $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/Tooltip');
144
145
146
            // Get record for element:
            $elRow = BackendUtility::getRecordWSOL($this->table, $this->moveUid);
            // Headerline: Icon, record title:
147
148
149
150
            $assigns['table'] = $this->table;
            $assigns['elRow'] = $elRow;
            $assigns['recordTooltip'] = BackendUtility::getRecordToolTip($elRow, $this->table);
            $assigns['recordTitle'] = BackendUtility::getRecordTitle($this->table, $elRow, true);
151
            // Make-copy checkbox (clicking this will reload the page with the GET var makeCopy set differently):
152
            $onClick = 'window.location.href=' . GeneralUtility::quoteJSvalue(GeneralUtility::linkThisScript(['makeCopy' => !$this->makeCopy])) . ';';
153
154
            $assigns['makeCopyChecked'] = $this->makeCopy ? ' checked="checked"' : '';
            $assigns['makeCopyOnClick'] = $onClick;
155
            // IF the table is "pages":
156
            if ((string)$this->table === 'pages') {
157
158
159
160
                // Get page record (if accessible):
                $pageInfo = BackendUtility::readPageAccess($this->page_id, $this->perms_clause);
                if (is_array($pageInfo) && $backendUser->isInWebMount($pageInfo['pid'], $this->perms_clause)) {
                    // Initialize the position map:
161
                    $posMap = GeneralUtility::makeInstance(PageMovingPagePositionMap::class);
162
163
164
165
166
167
                    $posMap->moveOrCopy = $this->makeCopy ? 'copy' : 'move';
                    // Print a "go-up" link IF there is a real parent page (and if the user has read-access to that page).
                    if ($pageInfo['pid']) {
                        $pidPageInfo = BackendUtility::readPageAccess($pageInfo['pid'], $this->perms_clause);
                        if (is_array($pidPageInfo)) {
                            if ($backendUser->isInWebMount($pidPageInfo['pid'], $this->perms_clause)) {
168
169
170
171
                                $assigns['pages']['goUpUrl'] = GeneralUtility::linkThisScript([
                                    'uid' => (int)$pageInfo['pid'],
                                    'moveUid' => $this->moveUid
                                ]);
172
                            } else {
173
                                $assigns['pages']['pidPageInfo'] = $pidPageInfo;
174
                            }
175
                            $assigns['pages']['pidRecordTitle'] = BackendUtility::getRecordTitle('pages', $pidPageInfo, true);
176
177
178
                        }
                    }
                    // Create the position tree:
179
                    $assigns['pages']['positionTree'] = $posMap->positionTree($this->page_id, $pageInfo, $this->perms_clause, $this->R_URI);
180
181
182
                }
            }
            // IF the table is "tt_content":
183
            if ((string)$this->table === 'tt_content') {
184
185
186
187
188
189
190
191
192
193
                // First, get the record:
                $tt_content_rec = BackendUtility::getRecord('tt_content', $this->moveUid);
                // ?
                if (!$this->input_moveUid) {
                    $this->page_id = $tt_content_rec['pid'];
                }
                // Checking if the parent page is readable:
                $pageInfo = BackendUtility::readPageAccess($this->page_id, $this->perms_clause);
                if (is_array($pageInfo) && $backendUser->isInWebMount($pageInfo['pid'], $this->perms_clause)) {
                    // Initialize the position map:
194
                    $posMap = GeneralUtility::makeInstance(ContentMovingPagePositionMap::class);
195
196
197
                    $posMap->moveOrCopy = $this->makeCopy ? 'copy' : 'move';
                    $posMap->cur_sys_language = $this->sys_language;
                    // Headerline for the parent page: Icon, record title:
198
199
200
                    $assigns['ttContent']['pageInfo'] = $pageInfo;
                    $assigns['ttContent']['recordTooltip'] = BackendUtility::getRecordToolTip($pageInfo, 'pages');
                    $assigns['ttContent']['recordTitle'] = BackendUtility::getRecordTitle('pages', $pageInfo, true);
201
202
203
204
                    // Load SHARED page-TSconfig settings and retrieve column list from there, if applicable:
                    // SHARED page-TSconfig settings.
                    // $modTSconfig_SHARED = BackendUtility::getModTSconfig($this->pageId, 'mod.SHARED');
                    $colPosArray = GeneralUtility::callUserFunction(\TYPO3\CMS\Backend\View\BackendLayoutView::class . '->getColPosListItemsParsed', $this->page_id, $this);
205
                    $colPosIds = [];
206
207
208
209
210
211
                    foreach ($colPosArray as $colPos) {
                        $colPosIds[] = $colPos[1];
                    }
                    // Removing duplicates, if any
                    $colPosList = implode(',', array_unique($colPosIds));
                    // Adding parent page-header and the content element columns from position-map:
212
                    $assigns['ttContent']['contentElementColumns'] = $posMap->printContentElementColumns($this->page_id, $this->moveUid, $colPosList, 1, $this->R_URI);
213
214
215
216
217
                    // Print a "go-up" link IF there is a real parent page (and if the user has read-access to that page).
                    if ($pageInfo['pid']) {
                        $pidPageInfo = BackendUtility::readPageAccess($pageInfo['pid'], $this->perms_clause);
                        if (is_array($pidPageInfo)) {
                            if ($backendUser->isInWebMount($pidPageInfo['pid'], $this->perms_clause)) {
218
                                $assigns['ttContent']['goUpUrl'] = GeneralUtility::linkThisScript([
219
220
                                    'uid' => (int)$pageInfo['pid'],
                                    'moveUid' => $this->moveUid
221
                                ]);
222
                            } else {
223
                                $assigns['ttContent']['pidPageInfo'] = $pidPageInfo;
224
                            }
225
                            $assigns['ttContent']['pidRecordTitle'] = BackendUtility::getRecordTitle('pages', $pidPageInfo, true);
226
227
228
                        }
                    }
                    // Create the position tree (for pages):
229
                    $assigns['ttContent']['positionTree'] = $posMap->positionTree($this->page_id, $pageInfo, $this->perms_clause, $this->R_URI);
230
231
                }
            }
232
233
234
235
236
237
238
239
240
            // Rendering of the output via fluid
            $view = GeneralUtility::makeInstance(StandaloneView::class);
            $view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates')]);
            $view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Partials')]);
            $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
                'EXT:backend/Resources/Private/Templates/ContentElement/MoveElement.html'
            ));
            $view->assignMultiple($assigns);
            $this->content .=  $view->render();
241
242
        }
        // Setting up the buttons and markers for docheader
243
        $this->getButtons();
244
        // Build the <body> for the module
245
        $this->moduleTemplate->setTitle($lang->getLL('movingElement'));
246
    }
247

248
249
250
251
252
    /**
     * Create the panel of buttons for submitting the form or otherwise perform operations.
     */
    protected function getButtons()
    {
253
        $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
254
        if ($this->page_id) {
255
            if ((string)$this->table === 'pages') {
256
257
258
259
                $cshButton = $buttonBar->makeHelpButton()
                    ->setModuleName('xMOD_csh_corebe')
                    ->setFieldName('move_el_pages');
                $buttonBar->addButton($cshButton);
260
            } elseif ((string)$this->table === 'tt_content') {
261
262
263
264
                $cshButton = $buttonBar->makeHelpButton()
                    ->setModuleName('xMOD_csh_corebe')
                    ->setFieldName('move_el_cs');
                $buttonBar->addButton($cshButton);
265
            }
266

267
            if ($this->R_URI) {
268
269
                $backButton = $buttonBar->makeLinkButton()
                    ->setHref($this->R_URI)
270
                    ->setTitle($this->getLanguageService()->getLL('goBack'))
271
272
273
274
275
                    ->setIcon($this->moduleTemplate->getIconFactory()->getIcon(
                        'actions-view-go-back',
                        Icon::SIZE_SMALL
                    ));
                $buttonBar->addButton($backButton);
276
277
278
            }
        }
    }
279

280
281
282
    /**
     * Returns LanguageService
     *
283
     * @return \TYPO3\CMS\Core\Localization\LanguageService
284
285
286
287
288
     */
    protected function getLanguageService()
    {
        return $GLOBALS['LANG'];
    }
289

290
291
292
293
294
295
296
297
298
    /**
     * Returns the current BE user.
     *
     * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
     */
    protected function getBackendUser()
    {
        return $GLOBALS['BE_USER'];
    }
299
}