[BUGFIX] IRRE records can't be expanded without an hidden field
authorOliver Hader <oliver@typo3.org>
Fri, 29 Jun 2012 16:52:52 +0000 (18:52 +0200)
committerOliver Hader <oliver.hader@typo3.org>
Wed, 4 Jul 2012 08:06:24 +0000 (10:06 +0200)
If no hidden field in TCA for IRRE child records, this will
lead to JavaScript errors on expanding the accordant child
record in the TCEforms view.

This regression has been introduced in issue #34303

Change-Id: Id980c001d9b33894e24581d6c89a20d3c795b34d
Fixes: #37615
Related: #34303
Releases: 6.0, 4.7, 4.6, 4.5
Reviewed-on: http://review.typo3.org/12577
Reviewed-by: Oliver Hader
Tested-by: Oliver Hader
t3lib/class.t3lib_tceforms_inline.php
t3lib/jsfunc.inline.js

index 3857ed3..1f653fc 100644 (file)
@@ -434,10 +434,10 @@ class t3lib_TCEforms_inline {
                        } else {
                                        // set additional field for processing for saving
                                $fields .= '<input type="hidden" name="' . $this->prependCmdFieldNames . $appendFormFieldNames . '[delete]" value="1" disabled="disabled" />';
-                               if(!$isExpanded) {
-                                       $checked = ($rec['hidden'] == 1) ? ' checked="checked"' : '';
-                                       $fields .= '<input type="checkbox" name="' . $this->prependFormFieldNames . $appendFormFieldNames . '[hidden]_0" value="1"'.$checked.' />';
-                                       $fields .= '<input type="input" name="' . $this->prependFormFieldNames . $appendFormFieldNames . '[hidden]" value="'.$rec['hidden'].'" />';
+                               if (!$isExpanded && !empty($GLOBALS['TCA'][$foreign_table]['ctrl']['enablecolumns']['disabled'])) {
+                                       $checked = (!empty($rec['hidden']) ? ' checked="checked"' : '');
+                                       $fields .= '<input type="checkbox" name="' . $this->prependFormFieldNames . $appendFormFieldNames . '[hidden]_0" value="1"' . $checked . ' />';
+                                       $fields .= '<input type="input" name="' . $this->prependFormFieldNames . $appendFormFieldNames . '[hidden]" value="' . $rec['hidden'] . '" />';
                                }
                        }
                                // if this record should be shown collapsed
index 09f8541..ec23164 100644 (file)
@@ -407,20 +407,35 @@ var inline = {
                }
        },
        domAddRecordDetails: function(objectId, objectPrefix, expandSingle, htmlData) {
+               var hiddenValue, formObj, valueObj;
                var objectDiv = $(objectId + '_fields');
                if (!objectDiv || objectDiv.innerHTML.substr(0,16) != '<!--notloaded-->')
                        return;
 
                var elName = this.parseObjectId('full', objectId, 2, 0, true);
 
-               var formObj = document.getElementsByName(elName+'[hidden]_0')[0];
-               var tempHiddenValue = formObj.checked;
-               formObj.remove();
-               document.getElementsByName(elName+'[hidden]')[0].remove();
+               formObj = document.getElementsByName(elName + '[hidden]_0');
+               valueObj = document.getElementsByName(elName + '[hidden]');
 
+                       // It might be the case that a child record
+                       // cannot be hidden at all (no hidden field)
+               if (formObj.length && valueObj.length) {
+                       hiddenValue = formObj[0].checked;
+                       formObj[0].remove();
+                       valueObj[0].remove();
+               }
+
+                       // Update DOM
                objectDiv.update(htmlData);
-               document.getElementsByName(elName+'[hidden]')[0].value = tempHiddenValue ? 1 : 0;
-               document.getElementsByName(elName+'[hidden]_0')[0].checked = tempHiddenValue;
+
+               formObj = document.getElementsByName(elName + '[hidden]_0');
+               valueObj = document.getElementsByName(elName + '[hidden]');
+
+                       // Set the hidden value again
+               if (formObj.length && valueObj.length) {
+                       valueObj[0].value = hiddenValue ? 1 : 0;
+                       formObj[0].checked = hiddenValue;
+               }
 
                        // remove loading-indicator
                if ($(objectId + '_icon')) {
@@ -718,22 +733,26 @@ var inline = {
        },
 
        enableDisableRecord: function(objectId) {
-               var elName = this.parseObjectId('full', objectId, 2, 0, true);
-               var currentUid = this.parseObjectId('none', objectId, 1);
-               var objectPrefix = this.parseObjectId('full', objectId, 0, 1);
-               var formObj = document.getElementsByName(elName+'[hidden]_0')[0];
-
-               formObj.click();
-
-               document.getElementsByName(elName+'[hidden]')[0].value = formObj.checked?1:0;
-               TBE_EDITOR.fieldChanged(objectPrefix,'1','hidden',elName+'[hidden]');
+               var elName = this.parseObjectId('full', objectId, 2, 0, true) + '[hidden]';
+               var formObj = document.getElementsByName(elName + '_0');
+               var valueObj = document.getElementsByName(elName);
+               var icon = $(objectId + '_disabled');
+
+                       // It might be the case that there's no hidden field
+               if (formObj.length && valueObj.length) {
+                       formObj[0].click();
+                       valueObj[0].value = formObj[0].checked ? 1 : 0;
+                       TBE_EDITOR.fieldChanged_fName(elName, elName);
+               }
 
-               if($(objectId+'_disabled').hasClassName('t3-icon-edit-hide')) {
-                       $(objectId+'_disabled').removeClassName ('t3-icon-edit-hide');
-                       $(objectId+'_disabled').addClassName('t3-icon-edit-unhide');
-               } else {
-                       $(objectId+'_disabled').removeClassName ('t3-icon-edit-unhide');
-                       $(objectId+'_disabled').addClassName('t3-icon-edit-hide');
+               if (icon) {
+                       if (icon.hasClassName('t3-icon-edit-hide')) {
+                               icon.removeClassName ('t3-icon-edit-hide');
+                               icon.addClassName('t3-icon-edit-unhide');
+                       } else {
+                               icon.removeClassName ('t3-icon-edit-unhide');
+                               icon.addClassName('t3-icon-edit-hide');
+                       }
                }
 
                return false;