[BUGFIX] Enable removing all selectable user groups
[TYPO3CMS/Extensions/sr_feuser_register.git] / Classes / View / EditView.php
1 <?php
2 namespace SJBR\SrFeuserRegister\View;
3
4 /*
5 * Copyright notice
6 *
7 * (c) 2007-2015 Stanislas Rolland <typo3(arobas)sjbr.ca>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * This script is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 */
24
25 use SJBR\SrFeuserRegister\Exception;
26 use SJBR\SrFeuserRegister\Security\Authentication;
27 use SJBR\SrFeuserRegister\Security\SecuredData;
28 use SJBR\SrFeuserRegister\Utility\CssUtility;
29 use SJBR\SrFeuserRegister\Utility\LocalizationUtility;
30 use SJBR\SrFeuserRegister\View\AbstractView;
31 use TYPO3\CMS\Core\Utility\GeneralUtility;
32
33 /**
34 * Edit view
35 */
36
37 class EditView extends AbstractView
38 {
39 /**
40 * Displays the record update form
41 *
42 * @param array $origArray: the array coming from the database
43 * @return string the template with substituted markers
44 */
45 public function render(array $dataArray, array $origArray, array $securedArray, $cmd, $cmdKey, $mode) {
46 $content = '';
47 $currentArray = $origArray;
48 if (isset($dataArray) && is_array($dataArray)) {
49 foreach ($dataArray as $key => $value) {
50 if (!is_array($value) || $mode === self::MODE_PREVIEW || $this->parameters->getFeUserData('doNotSave')) {
51 $currentArray[$key] = $value;
52 }
53 }
54 }
55 if ($cmdKey === 'password') {
56 $subpartMarker = '###TEMPLATE_SETFIXED_OK_APPROVE_INVITE###';
57 } else {
58 $subpartMarker = '###TEMPLATE_EDIT' . ($mode ? Marker::PREVIEW_SUFFIX : '') . '###';
59 }
60 $templateCode = $this->marker->getSubpart($this->marker->getTemplateCode(), $subpartMarker);
61 if (empty($templateCode)) {
62 $errorText = LocalizationUtility::translate('internal_no_subtemplate', $this->extensionName);
63 $errorText = sprintf($errorText, $subpartMarker);
64 throw new Exception($errorText, Exception::MISSING_SUBPART);
65 }
66 $isPreview = ($mode === self::MODE_PREVIEW);
67 if (!$this->conf['linkToPID'] || !$this->conf['linkToPIDAddButton'] || !$isPreview) {
68 $templateCode = $this->marker->substituteSubpart($templateCode, '###SUB_LINKTOPID_ADD_BUTTON###', '');
69 }
70 if (!$this->conf['delete']) {
71 $templateCode = $this->marker->substituteSubpart($templateCode, '###SUB_LINK_TO_DELETE###', '');
72 }
73 $infoFields = $this->data->getFieldList();
74 $requiredFields = $this->data->getRequiredFieldsArray($cmdKey);
75 $this->marker->addPasswordTransmissionMarkers($this->getUsePassword(), $this->getUsePasswordAgain());
76 $templateCode = $this->marker->removeRequired($templateCode, $this->data->getFailure(), $requiredFields, $infoFields, $this->data->getSpecialFieldList(), $cmdKey, $isPreview);
77 $this->marker->fillInMarkerArray($currentArray, $securedArray, '', true, 'FIELD_', true, $isPreview);
78 if ($cmdKey !== 'password') {
79 $this->marker->addStaticInfoMarkers($currentArray, $isPreview);
80 }
81 $this->marker->addTcaMarkers($currentArray, $origArray, $cmd, $cmdKey, $isPreview, $requiredFields);
82 $this->marker->addLabelMarkers($currentArray, $origArray, $securedArray, array(), $requiredFields, $infoFields, $this->data->getSpecialFieldList());
83 if ($cmdKey !== 'password') {
84 $this->marker->addAdditionalMarkers($infoFields, $cmd, $cmdKey, $currentArray, $isPreview);
85 }
86 $templateCode = $this->marker->removeStaticInfoSubparts($templateCode, $isPreview);
87 $this->marker->addEditFormHiddenFieldsMarkers($currentArray['uid'], Authentication::authCode($origArray, $this->conf, $this->conf['setfixed.']['EDIT.']['_FIELDLIST']), $cmd);
88 $this->marker->addHiddenFieldsMarkers($cmdKey, $mode, $this->conf[$cmdKey . '.']['useEmailAsUsername'], $this->conf[$cmdKey . '.']['fields'], $currentArray);
89 $this->marker->removePasswordMarkers();
90 $deleteUnusedMarkers = true;
91 $content .= $this->marker->substituteMarkerArray($templateCode, $this->marker->getMarkerArray(), '', false, $deleteUnusedMarkers);
92 if (!$isPreview) {
93 $form = $this->conf['formName'] ?: CssUtility::getClassName($this->prefixId, $this->theTable . '_form');
94 $modData = $this->data->modifyDataArrForFormUpdate($currentArray, $cmdKey);
95 $fields = $infoFields . ',' . $this->data->getAdditionalUpdateFields();
96 $fields = implode(',', array_intersect(explode(',', $fields), GeneralUtility::trimExplode(',', $this->conf[$cmdKey . '.']['fields'], true)));
97 $fields = SecuredData::getOpenFields($fields);
98 if (!empty($fields)) {
99 $updateJS = $this->getUpdateJS($modData, $form, 'FE[' . $this->theTable . ']', $fields);
100 }
101 $content .= $updateJS;
102 }
103 return $content;
104 }
105 }