[BUGFIX] Enable removing all selectable user groups 87/58687/2
authorStanislas Rolland <typo3@sjbr.ca>
Wed, 24 Oct 2018 23:33:05 +0000 (19:33 -0400)
committerStanislas Rolland <typo3@sjbr.ca>
Wed, 24 Oct 2018 23:35:05 +0000 (01:35 +0200)
Unsetting all usergroups on the creation or editing form had no effect.

Resolves: #86736
Change-Id: I90cbdc2cc316ce6108dab0d60d998b007bcbecf9
Reviewed-on: https://review.typo3.org/58687
Reviewed-by: Stanislas Rolland <typo3@sjbr.ca>
Tested-by: Stanislas Rolland <typo3@sjbr.ca>
ChangeLog
Classes/Domain/Data.php
Classes/Hooks/UsergroupHooks.php
Classes/View/CreateView.php
Classes/View/EditView.php

index f30a3b5..fe7be65 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+2018-10-24 Stanislas Rolland  <typo3(arobas)sjbr.ca>
+       * Resolves #86736: Removing all selectable user groups was not possible
+
 2018-10-23 Stanislas Rolland  <typo3(arobas)sjbr.ca>
        * Resolves #85925: PHP codeinspection returns errors
        * Resolves #84694: Backslash missing in user image preview link path
index 8cdeed0..9d5e2bf 100644 (file)
@@ -921,8 +921,8 @@ class Data
                                                                }
                                                                break;
                                                        case 'multiple':
-                                                               $fieldDataArray = array();
-                                                               if (!empty($dataValue)) {
+                                                               $fieldDataArray = [];
+                                                               if (!empty($dataArray[$theField]) && !empty($dataValue)) {
                                                                        if (is_array($dataValue)) {
                                                                                $fieldDataArray = $dataValue;
                                                                        } else if (is_string($dataValue)) {
index 02d3908..58c7c6f 100644 (file)
@@ -116,6 +116,7 @@ class UsergroupHooks
                $valuesArray = array();
                if (isset($origArray[$fieldname]) && is_array($origArray[$fieldname])) {
                        $valuesArray = $origArray[$fieldname];
+                       $keepValues = [];
                        if ($conf[$cmdKey . '.']['keepUnselectableUserGroups']) {
                                // Get usergroups that are not selectable
                                if (class_exists('TYPO3\\CMS\\Core\\Database\\ConnectionPool')) {
@@ -138,9 +139,8 @@ class UsergroupHooks
                                if (!empty($rowArray) && is_array($rowArray)) {
                                        $keepValues = array_keys($rowArray);
                                }
-                       } else {
-                               $keepValues = $this->getReservedValues($conf);
                        }
+                       $keepValues = array_unique(array_merge($keepValues, $this->getReservedValues($conf)));
                        $valuesArray = array_intersect($valuesArray, $keepValues);
                }
                if (isset($dataArray[$fieldname]) && is_array($dataArray[$fieldname])) {
index 113c3c1..c1dfbd3 100644 (file)
@@ -42,7 +42,14 @@ class CreateView extends AbstractView
         */
        public function render(array $dataArray, array $origArray, array $securedArray, $cmd, $cmdKey, $mode) {
                $content = '';
-               $currentArray = array_merge($origArray, $dataArray);
+               $currentArray = $origArray;
+               if (isset($dataArray) && is_array($dataArray)) {
+                       foreach ($dataArray as $key => $value) {
+                               if (!is_array($value) || $mode === self::MODE_PREVIEW || $this->parameters->getFeUserData('doNotSave')) {
+                                       $currentArray[$key] = $value;
+                               }
+                       }
+               }
 
                if ($this->theTable === 'fe_users') {
                        if ($this->getUsePassword() && !isset($currentArray['password'])) {
index b933bc6..8602136 100644 (file)
@@ -47,7 +47,7 @@ class EditView extends AbstractView
                $currentArray = $origArray;
                if (isset($dataArray) && is_array($dataArray)) {
                        foreach ($dataArray as $key => $value) {
-                               if (!is_array($value) || !empty($value)) {
+                               if (!is_array($value) || $mode === self::MODE_PREVIEW || $this->parameters->getFeUserData('doNotSave')) {
                                        $currentArray[$key] = $value;
                                }
                        }