[BUGFIX] Hide "Create ..." buttons, if maxitems is reached 57/40257/7
authorJonathan IROULIN <joniroutypo3@gmail.com>
Mon, 15 Jun 2015 15:54:29 +0000 (17:54 +0200)
committerBenjamin Mack <benni@typo3.org>
Wed, 17 Jun 2015 18:26:24 +0000 (20:26 +0200)
This patch hide "Creation relation", "Create new ..." and
"Select & Upload" button when the edit form is generated if there
is a maxitems limit in the TCA. The buttons are not immediately
hidden/shown if the number of relation changes. That would involve
JavaScript magic and could be done in a follow up.

Resolves: #45125
Releases: master
Change-Id: I725aee28568c67dfc3b2feebb62d39ec5432d149
Reviewed-on: http://review.typo3.org/40257
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Jan Helke <typo3@helke.de>
Tested-by: Jan Helke <typo3@helke.de>
Reviewed-by: Benjamin Mack <benni@typo3.org>
Tested-by: Benjamin Mack <benni@typo3.org>
typo3/sysext/backend/Classes/Form/Container/InlineControlContainer.php
typo3/sysext/backend/Resources/Public/JavaScript/DragUploader.js
typo3/sysext/backend/Resources/Public/JavaScript/jsfunc.inline.js

index 75e4265..a93c49f 100644 (file)
@@ -189,29 +189,33 @@ class InlineControlContainer extends AbstractContainer {
                                $localizationLinks .= ' ' . $this->getLevelInteractionLink('synchronize', $nameObject . '-' . $foreign_table, $config);
                        }
                }
-               // If it's required to select from possible child records (reusable children), add a selector box
-               if ($config['foreign_selector'] && $config['appearance']['showPossibleRecordsSelector'] !== FALSE) {
-                       // If not already set by the foreign_unique, set the possibleRecords here and the uniqueIds to an empty array
-                       if (!$config['foreign_unique']) {
-                               $possibleRecords = $this->getPossibleRecords($table, $field, $row, $config);
-                               $uniqueIds = array();
-                       }
-                       $selectorBox = $this->renderPossibleRecordsSelector($possibleRecords, $config, $uniqueIds);
-                       $html .= $selectorBox . $localizationLinks;
+
+               // Define how to show the "Create new record" link - if there are more than maxitems, hide it
+               if ($relatedRecords['count'] >= $maxItems || $uniqueMax > 0 && $relatedRecords['count'] >= $uniqueMax) {
+                       $config['inline']['inlineNewButtonStyle'] = 'display: none;';
+                       $config['inline']['inlineNewRelationButtonStyle'] = 'display: none;';
                }
+
                // Render the level links (create new record):
                $levelLinks = $this->getLevelInteractionLink('newRecord', $nameObject . '-' . $foreign_table, $config);
 
                // Wrap all inline fields of a record with a <div> (like a container)
                $html .= '<div class="form-group" id="' . $nameObject . '">';
-               // Define how to show the "Create new record" link - if there are more than maxitems, hide it
-               if ($relatedRecords['count'] >= $maxItems || $uniqueMax > 0 && $relatedRecords['count'] >= $uniqueMax) {
-                       $config['inline']['inlineNewButtonStyle'] = 'display: none;';
-               }
+
                // Add the level links before all child records:
                if ($config['appearance']['levelLinksPosition'] === 'both' || $config['appearance']['levelLinksPosition'] === 'top') {
                        $html .= '<div class="form-group">' . $levelLinks . $localizationLinks . '</div>';
                }
+               // If it's required to select from possible child records (reusable children), add a selector box
+               if ($config['foreign_selector'] && $config['appearance']['showPossibleRecordsSelector'] !== FALSE) {
+                       // If not already set by the foreign_unique, set the possibleRecords here and the uniqueIds to an empty array
+                       if (!$config['foreign_unique']) {
+                               $possibleRecords = $this->getPossibleRecords($table, $field, $row, $config);
+                               $uniqueIds = array();
+                       }
+                       $selectorBox = $this->renderPossibleRecordsSelector($possibleRecords, $config, $uniqueIds);
+                       $html .= $selectorBox . $localizationLinks;
+               }
                $title = $languageService->sL($parameterArray['fieldConf']['label']);
                $html .= '<div class="panel-group panel-hover" data-title="' . htmlspecialchars($title) . '" id="' . $nameObject . '_records">';
 
@@ -505,6 +509,7 @@ class InlineControlContainer extends AbstractContainer {
                $foreign_table = $config['foreign_table'];
                $allowed = $config['allowed'];
                $objectPrefix = $this->inlineStackProcessor->getCurrentStructureDomObjectIdPrefix($this->globalOptions['inlineFirstPid']) . '-' . $foreign_table;
+               $nameObject = $this->inlineStackProcessor->getCurrentStructureDomObjectIdPrefix($this->globalOptions['inlineFirstPid']);
                $mode = 'db';
                $showUpload = FALSE;
                if (!empty($config['appearance']['createNewRelationLinkTitle'])) {
@@ -529,8 +534,14 @@ class InlineControlContainer extends AbstractContainer {
                $browserParams = '|||' . $allowed . '|' . $objectPrefix . '|inline.checkUniqueElement||inline.importElement';
                $onClick = 'setFormValueOpenBrowser(' . GeneralUtility::quoteJSvalue($mode) . ', ' . GeneralUtility::quoteJSvalue($browserParams) . '); return false;';
 
+               $buttonStyle = '';
+               if (isset($config['inline']['inlineNewRelationButtonStyle'])) {
+                       $buttonStyle = ' style="' . $config['inline']['inlineNewRelationButtonStyle'] . '"';
+               }
+
                $item = '
-                       <a href="#" class="btn btn-default" onclick="' . htmlspecialchars($onClick) . '">
+                       <a href="#" class="btn btn-default inlineNewRelationButton ' . $this->inlineData['config'][$nameObject]['md5'] . '"
+                               ' . $buttonStyle . ' onclick="' . htmlspecialchars($onClick) . '">
                                ' . IconUtility::getSpriteIcon('actions-insert-record', array('title' => $createNewRelationText)) . '
                                ' . $createNewRelationText . '
                        </a>';
@@ -543,8 +554,8 @@ class InlineControlContainer extends AbstractContainer {
                                && $folder->checkActionPermission('add')
                        ) {
                                $maxFileSize = GeneralUtility::getMaxUploadFileSize() * 1024;
-                               $item .= ' <a href="#" class="btn btn-default t3js-drag-uploader"
-                                       style="display:none"
+                               $item .= ' <a href="#" class="btn btn-default t3js-drag-uploader inlineNewFileUploadButton ' . $this->inlineData['config'][$nameObject]['md5'] . '"
+                                       ' . $buttonStyle . '
                                        data-dropzone-target="#' . htmlspecialchars($this->inlineStackProcessor->getCurrentStructureDomObjectIdPrefix($this->globalOptions['inlineFirstPid'])) . '"
                                        data-insert-dropzone-before="1"
                                        data-file-irre-object="' . htmlspecialchars($objectPrefix) . '"
index 62758f3..9800e84 100644 (file)
@@ -123,7 +123,6 @@ define('TYPO3/CMS/Backend/DragUploader', ['jquery', 'TYPO3/CMS/Lang/Lang'], func
                };
 
                if (me.browserCapabilities.DnD) {
-                       me.$element.show();
                        me.$body.on('dragover', me.dragFileIntoDocument);
                        me.$body.on('dragend', me.dragAborted);
                        me.$body.on('drop', me.ignoreDrop);
index aa807e2..138ae9b 100644 (file)
@@ -792,6 +792,8 @@ var inline = {
                        var objectParent = this.parseObjectId('full', objectPrefix, 0, 1);
                        var md5 = this.getObjectMD5(objectParent);
                        this.hideElementsWithClassName('.inlineNewButton' + (md5 ? '.' + md5 : ''), objectParent);
+                       this.hideElementsWithClassName('.inlineNewRelationButton' + (md5 ? '.' + md5 : ''), objectParent);
+                       this.hideElementsWithClassName('.inlineNewFileUploadButton' + (md5 ? '.' + md5 : ''), objectParent);
                        this.hideElementsWithClassName('.inlineForeignSelector' + (md5 ? '.' + md5 : ''), 't3-form-field-item');
                }
 
@@ -994,6 +996,8 @@ var inline = {
                        var objectParent = this.parseObjectId('full', objectPrefix, 0, 1);
                        var md5 = this.getObjectMD5(objectParent);
                        this.showElementsWithClassName('.inlineNewButton' + (md5 ? '.' + md5 : ''), objectParent);
+                       this.showElementsWithClassName('.inlineNewRelationButton' + (md5 ? '.' + md5 : ''), objectParent);
+                       this.showElementsWithClassName('.inlineNewFileUploadButton' + (md5 ? '.' + md5 : ''), objectParent);
                        this.showElementsWithClassName('.inlineForeignSelector' + (md5 ? '.'+md5 : ''), 't3-form-field-item');
                }
                return false;