/
EditDocumentController.php
2782 lines (2534 loc) · 118 KB
/
EditDocumentController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Backend\Controller;
/*
* This file is part of the TYPO3 CMS project.
*
* 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.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Form\Exception\AccessDeniedException;
use TYPO3\CMS\Backend\Form\Exception\DatabaseRecordException;
use TYPO3\CMS\Backend\Form\FormDataCompiler;
use TYPO3\CMS\Backend\Form\FormDataGroup\TcaDatabaseRecord;
use TYPO3\CMS\Backend\Form\FormResultCompiler;
use TYPO3\CMS\Backend\Form\NodeFactory;
use TYPO3\CMS\Backend\Form\Utility\FormEngineUtility;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Backend\Template\Components\ButtonBar;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Compatibility\PublicMethodDeprecationTrait;
use TYPO3\CMS\Core\Compatibility\PublicPropertyDeprecationTrait;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Database\ReferenceIndex;
use TYPO3\CMS\Core\DataHandling\DataHandler;
use TYPO3\CMS\Core\Http\HtmlResponse;
use TYPO3\CMS\Core\Http\RedirectResponse;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Messaging\FlashMessageService;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Routing\SiteMatcher;
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
use TYPO3\CMS\Core\Type\Bitmask\Permission;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\HttpUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3\CMS\Core\Utility\PathUtility;
use TYPO3\CMS\Extbase\SignalSlot\Dispatcher;
use TYPO3\CMS\Frontend\Page\CacheHashCalculator;
use TYPO3\CMS\Frontend\Page\PageRepository;
/**
* Main backend controller almost always used if some database record is edited in the backend.
*
* Main job of this controller is to evaluate and sanitize $request parameters,
* call the DataHandler if records should be created or updated and
* execute FormEngine for record rendering.
*/
class EditDocumentController
{
use PublicMethodDeprecationTrait;
use PublicPropertyDeprecationTrait;
/**
* @deprecated since TYPO3 v9. These constants will be set to protected in TYPO3 v10.0
*/
public const DOCUMENT_CLOSE_MODE_DEFAULT = 0;
public const DOCUMENT_CLOSE_MODE_REDIRECT = 1; // works like DOCUMENT_CLOSE_MODE_DEFAULT
public const DOCUMENT_CLOSE_MODE_CLEAR_ALL = 3;
public const DOCUMENT_CLOSE_MODE_NO_REDIRECT = 4;
/**
* @var array
*/
private $deprecatedPublicMethods = [
'makeEditForm' => 'Using EditDocumentController::makeEditForm() is deprecated and will not be possible anymore in TYPO3 v10.0.',
'compileForm' => 'Using EditDocumentController::compileForm() is deprecated and will not be possible anymore in TYPO3 v10.0.',
'languageSwitch' => 'Using EditDocumentController::languageSwitch() is deprecated and will not be possible anymore in TYPO3 v10.0.',
'getLanguages' => 'Using EditDocumentController::getLanguages() is deprecated and will not be possible anymore in TYPO3 v10.0.',
'fixWSversioningInEditConf' => 'Using EditDocumentController::fixWSversioningInEditConf() is deprecated and will not be possible anymore in TYPO3 v10.0.',
'getRecordForEdit' => 'Using EditDocumentController::getRecordForEdit() is deprecated and will not be possible anymore in TYPO3 v10.0.',
];
/**
* Properties which have been moved to protected status from public
*
* @var array
*/
private $deprecatedPublicProperties = [
'editconf' => 'Using $editconf of class EditDocumentTemplate from the outside is discouraged, as this variable is only used for internal storage.',
'defVals' => 'Using $defVals of class EditDocumentTemplate from the outside is discouraged, as this variable is only used for internal storage.',
'overrideVals' => 'Using $overrideVals of class EditDocumentTemplate from the outside is discouraged, as this variable is only used for internal storage.',
'columnsOnly' => 'Using $columnsOnly of class EditDocumentTemplate from the outside is discouraged, as this variable is only used for internal storage.',
'returnUrl' => 'Using $returnUrl of class EditDocumentTemplate from the outside is discouraged, as this variable is only used for internal storage.',
'closeDoc' => 'Using $closeDoc of class EditDocumentTemplate from the outside is discouraged, as this variable is only used for internal storage.',
'doSave' => 'Using $doSave of class EditDocumentTemplate from the outside is discouraged, as this variable is only used for internal storage.',
'returnEditConf' => 'Using $returnEditConf of class EditDocumentTemplate from the outside is discouraged, as this variable is only used for internal storage.',
'uc' => 'Using $uc of class EditDocumentTemplate from the outside is discouraged, as this variable is only used for internal storage.',
'retUrl' => 'Using $retUrl of class EditDocumentTemplate from the outside is discouraged, as this variable is only used for internal storage.',
'R_URL_parts' => 'Using $R_URL_parts of class EditDocumentTemplate from the outside is discouraged, as this variable is only used for internal storage.',
'R_URL_getvars' => 'Using $R_URL_getvars of class EditDocumentTemplate from the outside is discouraged, as this variable is only used for internal storage.',
'storeArray' => 'Using $storeArray of class EditDocumentTemplate from the outside is discouraged, as this variable is only used for internal storage.',
'storeUrl' => 'Using $storeUrl of class EditDocumentTemplate from the outside is discouraged, as this variable is only used for internal storage.',
'storeUrlMd5' => 'Using $storeUrlMd5 of class EditDocumentTemplate from the outside is discouraged, as this variable is only used for internal storage.',
'docDat' => 'Using $docDat of class EditDocumentTemplate from the outside is discouraged, as this variable is only used for internal storage.',
'docHandler' => 'Using $docHandler of class EditDocumentTemplate from the outside is discouraged, as this variable is only used for internal storage.',
'cmd' => 'Using $cmd of class EditDocumentTemplate from the outside is discouraged, as this variable is only used for internal storage.',
'mirror' => 'Using $mirror of class EditDocumentTemplate from the outside is discouraged, as this variable is only used for internal storage.',
'cacheCmd' => 'Using $cacheCmd of class EditDocumentTemplate from the outside is discouraged, the variable will be removed.',
'redirect' => 'Using $redirect of class EditDocumentTemplate from the outside is discouraged, the variable will be removed.',
'returnNewPageId' => 'Using $returnNewPageId of class EditDocumentTemplate from the outside is discouraged, as this variable is only used for internal storage.',
'popViewId' => 'Using $popViewId of class EditDocumentTemplate from the outside is discouraged, as this variable is only used for internal storage.',
'popViewId_addParams' => 'Using $popViewId_addParams of class EditDocumentTemplate from the outside is discouraged, the variable will be removed.',
'viewUrl' => 'Using $viewUrl of class EditDocumentTemplate from the outside is discouraged, as this variable is only used for internal storage.',
'recTitle' => 'Using $recTitle of class EditDocumentTemplate from the outside is discouraged, as this variable is only used for internal storage.',
'noView' => 'Using $noView of class EditDocumentTemplate from the outside is discouraged, as this variable is only used for internal storage.',
'MCONF' => 'Using $MCONF of class EditDocumentTemplate from the outside is discouraged, the variable will be removed.',
'doc' => 'Using $doc of class EditDocumentTemplate from the outside is discouraged, the variable will be removed.',
'perms_clause' => 'Using $perms_clause of class EditDocumentTemplate from the outside is discouraged, as this variable is only used for internal storage.',
'template' => 'Using $template of class EditDocumentTemplate from the outside is discouraged, the variable will be removed.',
'content' => 'Using $content of class EditDocumentTemplate from the outside is discouraged, the variable will be removed.',
'R_URI' => 'Using $R_URI of class EditDocumentTemplate from the outside is discouraged, as this variable is only used for internal storage.',
'pageinfo' => 'Using $pageinfo of class EditDocumentTemplate from the outside is discouraged, as this variable is only used for internal storage.',
'storeTitle' => 'Using $storeTitle of class EditDocumentTemplate from the outside is discouraged, as this variable is only used for internal storage.',
'firstEl' => 'Using $firstEl of class EditDocumentTemplate from the outside is discouraged, as this variable is only used for internal storage.',
'errorC' => 'Using $errorC of class EditDocumentTemplate from the outside is discouraged, as this variable is only used for internal storage.',
'newC' => 'Using $newC of class EditDocumentTemplate from the outside is discouraged, as this variable is only used for internal storage.',
'viewId' => 'Using $viewId of class EditDocumentTemplate from the outside is discouraged, as this variable is only used for internal storage.',
'viewId_addParams' => 'Using $viewId_addParams of class EditDocumentTemplate from the outside is discouraged, as this variable is only used for internal storage.',
'modTSconfig' => 'Using $modTSconfig of class EditDocumentTemplate from the outside is discouraged, the variable will be removed.',
'dontStoreDocumentRef' => 'Using $dontStoreDocumentRef of class EditDocumentTemplate from the outside is discouraged, as this variable is only used for internal storage.',
];
/**
* An array looking approx like [tablename][list-of-ids]=command, eg. "&edit[pages][123]=edit".
*
* @see \TYPO3\CMS\Backend\Utility\BackendUtility::editOnClick()
* @var array
*/
protected $editconf = [];
/**
* Comma list of field names to edit. If specified, only those fields will be rendered.
* Otherwise all (available) fields in the record are shown according to the TCA type.
*
* @var string|null
*/
protected $columnsOnly;
/**
* Default values for fields
*
* @var array|null [table][field]
*/
protected $defVals;
/**
* Array of values to force being set as hidden fields in FormEngine
*
* @var array|null [table][field]
*/
protected $overrideVals;
/**
* If set, this value will be set in $this->retUrl as "returnUrl", if not,
* $this->retUrl will link to dummy controller
*
* @var string|null
*/
protected $returnUrl;
/**
* Prepared return URL. Contains the URL that we should return to from FormEngine if
* close button is clicked. Usually passed along as 'returnUrl', but falls back to
* "dummy" controller.
*
* @var string
*/
protected $retUrl;
/**
* Close document command. One of the DOCUMENT_CLOSE_MODE_* constants above
*
* @var int
*/
protected $closeDoc;
/**
* If true, the processing of incoming data will be performed as if a save-button is pressed.
* Used in the forms as a hidden field which can be set through
* JavaScript if the form is somehow submitted by JavaScript.
*
* @var bool
*/
protected $doSave;
/**
* Main DataHandler datamap array
*
* @var array
* @todo: Will be set protected later, still used by ConditionMatcher
* @internal Will be removed / protected in TYPO3 v10.0 without further notice
*/
public $data;
/**
* Main DataHandler cmdmap array
*
* @var array
*/
protected $cmd;
/**
* DataHandler 'mirror' input
*
* @var array
*/
protected $mirror;
/**
* @var string
* @deprecated since TYPO3 v9, will be removed in TYPO3 v10.0, unused
*/
protected $cacheCmd;
/**
* @var string
* @deprecated since TYPO3 v9, will be removed in TYPO3 v10.0, unused
*/
protected $redirect;
/**
* Boolean: If set, then the GET var "&id=" will be added to the
* retUrl string so that the NEW id of something is returned to the script calling the form.
*
* @var bool
*/
protected $returnNewPageId = false;
/**
* Updated values for backendUser->uc. Used for new inline records to mark them
* as expanded: uc[inlineView][...]
*
* @var array|null
*/
protected $uc;
/**
* ID for displaying the page in the frontend, "save and view"
*
* @var int
*/
protected $popViewId;
/**
* @var string
* @deprecated since TYPO3 v9, will be removed in TYPO3 v10.0, unused
*/
protected $popViewId_addParams;
/**
* Alternative URL for viewing the frontend pages.
*
* @var string
*/
protected $viewUrl;
/**
* Alternative title for the document handler.
*
* @var string
*/
protected $recTitle;
/**
* If set, then no save & view button is printed
*
* @var bool
*/
protected $noView;
/**
* @var string
*/
protected $perms_clause;
/**
* If true, $this->editconf array is added a redirect response, used by Wizard/AddController
*
* @var bool
*/
protected $returnEditConf;
/**
* Workspace used for the editing action.
*
* @var string|null
*/
protected $workspace;
/**
* @var \TYPO3\CMS\Backend\Template\DocumentTemplate
* @deprecated since TYPO3 v9, will be removed in TYPO3 v10.0, unused
*/
protected $doc;
/**
* @deprecated since TYPO3 v9, will be removed in TYPO3 v10.0, unused
*/
protected $template;
/**
* @deprecated since TYPO3 v9, will be removed in TYPO3 v10.0, unused
*/
protected $content;
/**
* parse_url() of current requested URI, contains ['path'] and ['query'] parts.
*
* @var array
*/
protected $R_URL_parts;
/**
* Contains $request query parameters. This array is the foundation for creating
* the R_URI internal var which becomes the url to which forms are submitted
*
* @var array
*/
protected $R_URL_getvars;
/**
* Set to the URL of this script including variables which is needed to re-display the form.
*
* @var string
*/
protected $R_URI;
/**
* @var array
* @deprecated since TYPO3 v9, will be removed in TYPO3 v10.0, unused
*/
protected $MCONF;
/**
* @var array
*/
protected $pageinfo;
/**
* Is loaded with the "title" of the currently "open document"
* used for the open document toolbar
*
* @var string
*/
protected $storeTitle = '';
/**
* Contains an array with key/value pairs of GET parameters needed to reach the
* current document displayed - used in the 'open documents' toolbar.
*
* @var array
*/
protected $storeArray;
/**
* $this->storeArray imploded to url
*
* @var string
*/
protected $storeUrl;
/**
* md5 hash of storeURL, used to identify a single open document in backend user uc
*
* @var string
*/
protected $storeUrlMd5;
/**
* Backend user session data of this module
*
* @var array
*/
protected $docDat;
/**
* An array of the "open documents" - keys are md5 hashes (see $storeUrlMd5) identifying
* the various documents on the GET parameter list needed to open it. The values are
* arrays with 0,1,2 keys with information about the document (see compileStoreData()).
* The docHandler variable is stored in the $docDat session data, key "0".
*
* @var array
*/
protected $docHandler;
/**
* Array of the elements to create edit forms for.
*
* @var array
* @todo: Will be set protected later, still used by ConditionMatcher
* @internal Will be removed / protected in TYPO3 v10.0 without further notice
*/
public $elementsData;
/**
* Pointer to the first element in $elementsData
*
* @var array
*/
protected $firstEl;
/**
* Counter, used to count the number of errors (when users do not have edit permissions)
*
* @var int
*/
protected $errorC;
/**
* Counter, used to count the number of new record forms displayed
*
* @var int
*/
protected $newC;
/**
* Is set to the pid value of the last shown record - thus indicating which page to
* show when clicking the SAVE/VIEW button
*
* @var int
*/
protected $viewId;
/**
* Is set to additional parameters (like "&L=xxx") if the record supports it.
*
* @var string
*/
protected $viewId_addParams;
/**
* @deprecated since TYPO3 v9, will be removed in TYPO3 v10.0, unused
*/
protected $modTSconfig = [];
/**
* @var FormResultCompiler
*/
protected $formResultCompiler;
/**
* Used internally to disable the storage of the document reference (eg. new records)
*
* @var bool
*/
protected $dontStoreDocumentRef = 0;
/**
* @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher
*/
protected $signalSlotDispatcher;
/**
* Stores information needed to preview the currently saved record
*
* @var array
*/
protected $previewData = [];
/**
* ModuleTemplate object
*
* @var ModuleTemplate
*/
protected $moduleTemplate;
/**
* Check if a record has been saved
*
* @var bool
*/
protected $isSavedRecord;
/**
* Check if a page in free translation mode
*
* @var bool
*/
protected $isPageInFreeTranslationMode = false;
/**
* Constructor
*/
public function __construct()
{
$this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
$this->moduleTemplate->setUiBlock(true);
// @todo Used by TYPO3\CMS\Backend\Configuration\TypoScript\ConditionMatching
$GLOBALS['SOBE'] = $this;
$this->getLanguageService()->includeLLFile('EXT:backend/Resources/Private/Language/locallang_alt_doc.xlf');
}
/**
* Main dispatcher entry method registered as "record_edit" end point
*
* @param ServerRequestInterface $request the current request
* @return ResponseInterface the response with the content
*/
public function mainAction(ServerRequestInterface $request): ResponseInterface
{
// Unlock all locked records
BackendUtility::lockRecords();
if ($response = $this->preInit($request)) {
return $response;
}
// Process incoming data via DataHandler?
$parsedBody = $request->getParsedBody();
if ($this->doSave
|| isset($parsedBody['_savedok'])
|| isset($parsedBody['_saveandclosedok'])
|| isset($parsedBody['_savedokview'])
|| isset($parsedBody['_savedoknew'])
|| isset($parsedBody['_duplicatedoc'])
) {
if ($response = $this->processData($request)) {
return $response;
}
}
$this->init($request);
$this->main($request);
return new HtmlResponse($this->moduleTemplate->renderContent());
}
/**
* First initialization, always called, even before processData() executes DataHandler processing.
*
* @param ServerRequestInterface $request
* @return ResponseInterface|null Possible redirect response
*/
public function preInit(ServerRequestInterface $request = null): ?ResponseInterface
{
if ($request === null) {
// Missing argument? This method must have been called from outside.
// Method will be protected and $request mandatory in TYPO3 v10.0, giving core freedom to move stuff around
// New v10 signature: "protected function preInit(ServerRequestInterface $request): ?ResponseInterface"
// @deprecated since TYPO3 v9, method argument $request will be set to mandatory
trigger_error('EditDocumentController->preInit() will be set to protected in TYPO3 v10.0. Do not call from other extension.', E_USER_DEPRECATED);
$request = $GLOBALS['TYPO3_REQUEST'];
}
if ($response = $this->localizationRedirect($request)) {
return $response;
}
$parsedBody = $request->getParsedBody();
$queryParams = $request->getQueryParams();
$this->editconf = $parsedBody['edit'] ?? $queryParams['edit'] ?? [];
$this->defVals = $parsedBody['defVals'] ?? $queryParams['defVals'] ?? null;
$this->overrideVals = $parsedBody['overrideVals'] ?? $queryParams['overrideVals'] ?? null;
$this->columnsOnly = $parsedBody['columnsOnly'] ?? $queryParams['columnsOnly'] ?? null;
$this->returnUrl = GeneralUtility::sanitizeLocalUrl($parsedBody['returnUrl'] ?? $queryParams['returnUrl'] ?? null);
$this->closeDoc = (int)($parsedBody['closeDoc'] ?? $queryParams['closeDoc'] ?? self::DOCUMENT_CLOSE_MODE_DEFAULT);
$this->doSave = (bool)($parsedBody['doSave'] ?? $queryParams['doSave'] ?? false);
$this->returnEditConf = (bool)($parsedBody['returnEditConf'] ?? $queryParams['returnEditConf'] ?? false);
$this->workspace = $parsedBody['workspace'] ?? $queryParams['workspace'] ?? null;
$this->uc = $parsedBody['uc'] ?? $queryParams['uc'] ?? null;
// Set overrideVals as default values if defVals does not exist.
// @todo: Why?
if (!is_array($this->defVals) && is_array($this->overrideVals)) {
$this->defVals = $this->overrideVals;
}
// Set final return URL
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
$this->retUrl = $this->returnUrl ?: (string)$uriBuilder->buildUriFromRoute('dummy');
// Change $this->editconf if versioning applies to any of the records
$this->fixWSversioningInEditConf();
// Prepare R_URL (request url)
$this->R_URL_parts = parse_url($request->getAttribute('normalizedParams')->getRequestUri());
$this->R_URL_getvars = $queryParams;
$this->R_URL_getvars['edit'] = $this->editconf;
// Prepare 'open documents' url, this is later modified again various times
$this->compileStoreData();
// Backend user session data of this module
$this->docDat = $this->getBackendUser()->getModuleData('FormEngine', 'ses');
$this->docHandler = $this->docDat[0];
// Close document if a request for closing the document has been sent
if ((int)$this->closeDoc > self::DOCUMENT_CLOSE_MODE_DEFAULT) {
if ($response = $this->closeDocument($this->closeDoc, $request)) {
return $response;
}
}
// Sets a temporary workspace, this request is based on
if ($this->workspace !== null) {
$this->getBackendUser()->setTemporaryWorkspace($this->workspace);
}
$this->emitFunctionAfterSignal('preInit', $request);
return null;
}
/**
* Detects, if a save command has been triggered.
*
* @return bool TRUE, then save the document (data submitted)
* @deprecated since TYPO3 v9, will be removed in TYPO3 v10.0
*/
public function doProcessData()
{
trigger_error('EditDocumentController->doProcessData() will be removed in TYPO3 v10.0.', E_USER_DEPRECATED);
$out = $this->doSave
|| isset($_POST['_savedok'])
|| isset($_POST['_saveandclosedok'])
|| isset($_POST['_savedokview'])
|| isset($_POST['_savedoknew'])
|| isset($_POST['_duplicatedoc']);
return $out;
}
/**
* Do processing of data, submitting it to DataHandler. May return a RedirectResponse
*
* @param ServerRequestInterface $request
* @return ResponseInterface|null
*/
public function processData(ServerRequestInterface $request = null): ?ResponseInterface
{
// @deprecated Variable can be removed in TYPO3 v10.0
$deprecatedCaller = false;
if ($request === null) {
// Missing argument? This method must have been called from outside.
// Method will be protected and $request mandatory in TYPO3 v10.0, giving core freedom to move stuff around
// New v10 signature: "protected function processData(ServerRequestInterface $request): ?ResponseInterface"
// @deprecated since TYPO3 v9, method argument $request will be set to mandatory
trigger_error('EditDocumentController->processData() will be set to protected in TYPO3 v10.0. Do not call from other extension.', E_USER_DEPRECATED);
$request = $GLOBALS['TYPO3_REQUEST'];
$deprecatedCaller = true;
}
$parsedBody = $request->getParsedBody();
$queryParams = $request->getQueryParams();
$beUser = $this->getBackendUser();
// Processing related GET / POST vars
$this->data = $parsedBody['data'] ?? $queryParams['data'] ?? [];
$this->cmd = $parsedBody['cmd'] ?? $queryParams['cmd'] ?? [];
$this->mirror = $parsedBody['mirror'] ?? $queryParams['mirror'] ?? [];
// @deprecated property cacheCmd is unused and can be removed in TYPO3 v10.0
$this->cacheCmd = $parsedBody['cacheCmd'] ?? $queryParams['cacheCmd'] ?? null;
// @deprecated property redirect is unused and can be removed in TYPO3 v10.0
$this->redirect = $parsedBody['redirect'] ?? $queryParams['redirect'] ?? null;
$this->returnNewPageId = (bool)($parsedBody['returnNewPageId'] ?? $queryParams['returnNewPageId'] ?? false);
// Only options related to $this->data submission are included here
$tce = GeneralUtility::makeInstance(DataHandler::class);
$tce->setControl($parsedBody['control'] ?? $queryParams['control'] ?? []);
// Set internal vars
if (isset($beUser->uc['neverHideAtCopy']) && $beUser->uc['neverHideAtCopy']) {
$tce->neverHideAtCopy = 1;
}
// Load DataHandler with data
$tce->start($this->data, $this->cmd);
if (is_array($this->mirror)) {
$tce->setMirror($this->mirror);
}
// Perform the saving operation with DataHandler:
if ($this->doSave === true) {
// @todo: Make DataHandler understand UploadedFileInterface and submit $request->getUploadedFiles() instead of $_FILES here
$tce->process_uploads($_FILES);
$tce->process_datamap();
$tce->process_cmdmap();
}
// If pages are being edited, we set an instruction about updating the page tree after this operation.
if ($tce->pagetreeNeedsRefresh
&& (isset($this->data['pages']) || $beUser->workspace != 0 && !empty($this->data))
) {
BackendUtility::setUpdateSignal('updatePageTree');
}
// If there was saved any new items, load them:
if (!empty($tce->substNEWwithIDs_table)) {
// Save the expanded/collapsed states for new inline records, if any
FormEngineUtility::updateInlineView($this->uc, $tce);
$newEditConf = [];
foreach ($this->editconf as $tableName => $tableCmds) {
$keys = array_keys($tce->substNEWwithIDs_table, $tableName);
if (!empty($keys)) {
foreach ($keys as $key) {
$editId = $tce->substNEWwithIDs[$key];
// Check if the $editId isn't a child record of an IRRE action
if (!(is_array($tce->newRelatedIDs[$tableName])
&& in_array($editId, $tce->newRelatedIDs[$tableName]))
) {
// Translate new id to the workspace version
if ($versionRec = BackendUtility::getWorkspaceVersionOfRecord(
$beUser->workspace,
$tableName,
$editId,
'uid'
)) {
$editId = $versionRec['uid'];
}
$newEditConf[$tableName][$editId] = 'edit';
}
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
// Traverse all new records and forge the content of ->editconf so we can continue to edit these records!
if ($tableName === 'pages'
&& $this->retUrl != (string)$uriBuilder->buildUriFromRoute('dummy')
&& $this->returnNewPageId
) {
$this->retUrl .= '&id=' . $tce->substNEWwithIDs[$key];
}
}
} else {
$newEditConf[$tableName] = $tableCmds;
}
}
// Reset editconf if newEditConf has values
if (!empty($newEditConf)) {
$this->editconf = $newEditConf;
}
// Finally, set the editconf array in the "getvars" so they will be passed along in URLs as needed.
$this->R_URL_getvars['edit'] = $this->editconf;
// Unset default values since we don't need them anymore.
unset($this->R_URL_getvars['defVals']);
// Recompile the store* values since editconf changed
$this->compileStoreData();
}
// See if any records was auto-created as new versions?
if (!empty($tce->autoVersionIdMap)) {
$this->fixWSversioningInEditConf($tce->autoVersionIdMap);
}
// If a document is saved and a new one is created right after.
if (isset($parsedBody['_savedoknew']) && is_array($this->editconf)) {
if ($redirect = $this->closeDocument(self::DOCUMENT_CLOSE_MODE_NO_REDIRECT, $request)) {
return $redirect;
}
// Find the current table
reset($this->editconf);
$nTable = key($this->editconf);
// Finding the first id, getting the records pid+uid
reset($this->editconf[$nTable]);
$nUid = key($this->editconf[$nTable]);
$recordFields = 'pid,uid';
if (!empty($GLOBALS['TCA'][$nTable]['ctrl']['versioningWS'])) {
$recordFields .= ',t3ver_oid';
}
$nRec = BackendUtility::getRecord($nTable, $nUid, $recordFields);
// Determine insertion mode: 'top' is self-explaining,
// otherwise new elements are inserted after one using a negative uid
$insertRecordOnTop = ($this->getTsConfigOption($nTable, 'saveDocNew') === 'top');
// Setting a blank editconf array for a new record:
$this->editconf = [];
// Determine related page ID for regular live context
if ($nRec['pid'] != -1) {
if ($insertRecordOnTop) {
$relatedPageId = $nRec['pid'];
} else {
$relatedPageId = -$nRec['uid'];
}
} else {
// Determine related page ID for workspace context
if ($insertRecordOnTop) {
// Fetch live version of workspace version since the pid value is always -1 in workspaces
$liveRecord = BackendUtility::getRecord($nTable, $nRec['t3ver_oid'], $recordFields);
$relatedPageId = $liveRecord['pid'];
} else {
// Use uid of live version of workspace version
$relatedPageId = -$nRec['t3ver_oid'];
}
}
$this->editconf[$nTable][$relatedPageId] = 'new';
// Finally, set the editconf array in the "getvars" so they will be passed along in URLs as needed.
$this->R_URL_getvars['edit'] = $this->editconf;
// Recompile the store* values since editconf changed...
$this->compileStoreData();
}
// If a document should be duplicated.
if (isset($parsedBody['_duplicatedoc']) && is_array($this->editconf)) {
$this->closeDocument(self::DOCUMENT_CLOSE_MODE_NO_REDIRECT, $request);
// Find current table
reset($this->editconf);
$nTable = key($this->editconf);
// Find the first id, getting the records pid+uid
reset($this->editconf[$nTable]);
$nUid = key($this->editconf[$nTable]);
if (!MathUtility::canBeInterpretedAsInteger($nUid)) {
$nUid = $tce->substNEWwithIDs[$nUid];
}
$recordFields = 'pid,uid';
if (!empty($GLOBALS['TCA'][$nTable]['ctrl']['versioningWS'])) {
$recordFields .= ',t3ver_oid';
}
$nRec = BackendUtility::getRecord($nTable, $nUid, $recordFields);
// Setting a blank editconf array for a new record:
$this->editconf = [];
if ($nRec['pid'] != -1) {
$relatedPageId = -$nRec['uid'];
} else {
$relatedPageId = -$nRec['t3ver_oid'];
}
/** @var \TYPO3\CMS\Core\DataHandling\DataHandler $duplicateTce */
$duplicateTce = GeneralUtility::makeInstance(DataHandler::class);
$duplicateCmd = [
$nTable => [
$nUid => [
'copy' => $relatedPageId
]
]
];
$duplicateTce->start([], $duplicateCmd);
$duplicateTce->process_cmdmap();
$duplicateMappingArray = $duplicateTce->copyMappingArray;
$duplicateUid = $duplicateMappingArray[$nTable][$nUid];
if ($nTable === 'pages') {
BackendUtility::setUpdateSignal('updatePageTree');
}
$this->editconf[$nTable][$duplicateUid] = 'edit';
// Finally, set the editconf array in the "getvars" so they will be passed along in URLs as needed.
$this->R_URL_getvars['edit'] = $this->editconf;
// Recompile the store* values since editconf changed...
$this->compileStoreData();
// Inform the user of the duplication
$flashMessage = GeneralUtility::makeInstance(
FlashMessage::class,
$this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.recordDuplicated'),
'',
FlashMessage::OK
);
$flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
$defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
$defaultFlashMessageQueue->enqueue($flashMessage);
}
// If a preview is requested
if (isset($parsedBody['_savedokview'])) {
// Get the first table and id of the data array from DataHandler
$table = reset(array_keys($this->data));
$id = reset(array_keys($this->data[$table]));
if (!MathUtility::canBeInterpretedAsInteger($id)) {
$id = $tce->substNEWwithIDs[$id];
}
// Store this information for later use
$this->previewData['table'] = $table;
$this->previewData['id'] = $id;
}
$tce->printLogErrorMessages();
if ((int)$this->closeDoc < self::DOCUMENT_CLOSE_MODE_DEFAULT
|| isset($parsedBody['_saveandclosedok'])
) {
// Redirect if element should be closed after save
$possibleRedirect = $this->closeDocument(abs($this->closeDoc), $request);
if ($deprecatedCaller && $possibleRedirect) {
// @deprecated fall back if method has been called from outside. This if can be removed in TYPO3 v10.0
HttpUtility::redirect($possibleRedirect->getHeaders()['location'][0]);
}
return $possibleRedirect;
}
return null;
}
/**
* Initialize the view part of the controller logic.
*
* @param ServerRequestInterface $request
*/
public function init(ServerRequestInterface $request = null): void
{
if ($request === null) {
// Missing argument? This method must have been called from outside.
// Method will be protected and $request mandatory in TYPO3 v10.0, giving core freedom to move stuff around
// New v10 signature: "protected function init(ServerRequestInterface $request): void
// @deprecated since TYPO3 v9, method argument $request will be set to mandatory
trigger_error('EditDocumentController->init() will be set to protected in TYPO3 v10.0. Do not call from other extension.', E_USER_DEPRECATED);
$request = $GLOBALS['TYPO3_REQUEST'];
}
$parsedBody = $request->getParsedBody();
$queryParams = $request->getQueryParams();
$beUser = $this->getBackendUser();
// @deprecated since TYPO3 v9, will be removed in TYPO3 v10.0, unused, remove call in TYPO3 v10.0
$this->popViewId_addParams = $parsedBody['popViewId_addParams'] ?? $queryParams['popViewId_addParams'] ?? '';
$this->popViewId = (int)($parsedBody['popViewId'] ?? $queryParams['popViewId'] ?? 0);
$this->viewUrl = (string)($parsedBody['viewUrl'] ?? $queryParams['viewUrl'] ?? '');
$this->recTitle = (string)($parsedBody['recTitle'] ?? $queryParams['recTitle'] ?? '');
$this->noView = (bool)($parsedBody['noView'] ?? $queryParams['noView'] ?? false);
$this->perms_clause = $beUser->getPagePermsClause(Permission::PAGE_SHOW);
// Set other internal variables:
$this->R_URL_getvars['returnUrl'] = $this->retUrl;
$this->R_URI = $this->R_URL_parts['path'] . HttpUtility::buildQueryString($this->R_URL_getvars, '?');
// @deprecated since TYPO3 v9, will be removed in TYPO3 v10.0, unused
$this->MCONF['name'] = 'xMOD_alt_doc.php';
// @deprecated since TYPO3 v9, will be removed in TYPO3 v10.0, unused
$this->doc = $GLOBALS['TBE_TEMPLATE'];
$pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
$pageRenderer->addInlineLanguageLabelFile('EXT:backend/Resources/Private/Language/locallang_alt_doc.xlf');
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
// override the default jumpToUrl
$this->moduleTemplate->addJavaScriptCode(
'jumpToUrl',
'
// Info view:
function launchView(table,uid) {
console.warn(\'Calling launchView() has been deprecated in TYPO3 v9 and will be removed in TYPO3 v10.0\');
var thePreviewWindow = window.open(
' . GeneralUtility::quoteJSvalue((string)$uriBuilder->buildUriFromRoute('show_item') . '&table=') . ' + encodeURIComponent(table) + "&uid=" + encodeURIComponent(uid),
"ShowItem" + Math.random().toString(16).slice(2),
"height=300,width=410,status=0,menubar=0,resizable=0,location=0,directories=0,scrollbars=1,toolbar=0"
);
if (thePreviewWindow && thePreviewWindow.focus) {
thePreviewWindow.focus();
}
}
function deleteRecord(table,id,url) {
window.location.href = ' . GeneralUtility::quoteJSvalue((string)$uriBuilder->buildUriFromRoute('tce_db') . '&cmd[') . '+table+"]["+id+"][delete]=1&redirect="+escape(url);
}
' . (isset($parsedBody['_savedokview']) && $this->popViewId ? $this->generatePreviewCode() : '')
);
// Set context sensitive menu
$this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu');
$this->emitFunctionAfterSignal('init', $request);
}
/**
* Generate the Javascript for opening the preview window
*
* @return string
*/
protected function generatePreviewCode(): string
{
$previewPageId = $this->getPreviewPageId();
$previewPageRootLine = BackendUtility::BEgetRootLine($previewPageId);
$anchorSection = $this->getPreviewUrlAnchorSection();
$previewUrlParameters = $this->getPreviewUrlParameters($previewPageId);
return '
if (window.opener) {
'
. BackendUtility::viewOnClick(
$previewPageId,
'',
$previewPageRootLine,
$anchorSection,
$this->viewUrl,
$previewUrlParameters,
false
)
. '
} else {
'
. BackendUtility::viewOnClick(
$previewPageId,
'',
$previewPageRootLine,
$anchorSection,
$this->viewUrl,
$previewUrlParameters
)
. '
}';
}
/**