[BUGFIX] Allow same configuration key in multiple extensions 31/60831/6
authorJonas Eberle <flightvision@googlemail.com>
Mon, 27 May 2019 19:34:10 +0000 (21:34 +0200)
committerBenni Mack <benni@typo3.org>
Wed, 12 Jun 2019 04:18:55 +0000 (06:18 +0200)
Fix two issues in the extension configuration tool if more than one
extension is using the same configuration key:

* Remove duplicate HTML IDs in extension configuration tool
* Correctly add hidden fields with value=0 for checkboxes within every
  sub-<form>, not only on first occurence (first extension) of any given
  configuration key

Resolves: #88426
Releases: master, 9.5
Change-Id: Ifbdb3b495443aa5521a4b5265ae3c29c2bc222b8
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/60831
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Guido Schmechel <guido.schmechel@brandung.de>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Guido Schmechel <guido.schmechel@brandung.de>
Reviewed-by: Benni Mack <benni@typo3.org>
typo3/sysext/install/Classes/Service/ExtensionConfigurationService.php
typo3/sysext/install/Classes/ViewHelpers/Form/TypoScriptConstantsViewHelper.php
typo3/sysext/install/Resources/Private/Partials/Settings/ExtensionConfiguration/ExtensionForm.html

index 0270a3b..d0aa0ae 100644 (file)
@@ -226,6 +226,7 @@ class ExtensionConfigurationService
             ) {
                 $theConstants[$configurationOptionName]['subcat_label'] = $this->subCategories[$configurationOption['subcat_name']][0];
             }
+            $theConstants[$configurationOptionName]['extensionKey'] = $extensionKey;
         }
         return $theConstants;
     }
index 500eddd..9874f26 100644 (file)
@@ -98,13 +98,12 @@ class TypoScriptConstantsViewHelper extends AbstractTagBasedViewHelper
      */
     protected function renderColorPicker(array $configuration): string
     {
-        $elementId = 'em-' . $configuration['name'];
         $elementName = $this->getName($configuration);
 
         // configure the field
         $this->tag->setTagName('input');
         $this->tag->addAttribute('type', 'text');
-        $this->tag->addAttribute('id', $elementId);
+        $this->addIdAttribute($configuration);
         $this->tag->addAttribute('name', $elementName);
         $this->tag->addAttribute('data-formengine-input-name', $elementName);
         $this->tag->addAttribute('class', 'form-control');
@@ -134,7 +133,7 @@ class TypoScriptConstantsViewHelper extends AbstractTagBasedViewHelper
     {
         $this->tag->setTagName('input');
         $this->tag->addAttribute('type', 'text');
-        $this->tag->addAttribute('id', 'em-' . $configuration['name']);
+        $this->addIdAttribute($configuration);
         $this->tag->addAttribute('name', $this->getName($configuration));
         $this->tag->addAttribute('class', 'form-control t3js-emconf-offset');
         if ($configuration['value'] !== null) {
@@ -153,7 +152,7 @@ class TypoScriptConstantsViewHelper extends AbstractTagBasedViewHelper
     {
         $this->tag->setTagName('input');
         $this->tag->addAttribute('type', 'text');
-        $this->tag->addAttribute('id', 'em-' . $configuration['name']);
+        $this->addIdAttribute($configuration);
         $this->tag->addAttribute('name', $this->getName($configuration));
         $this->tag->addAttribute('class', 'form-control t3js-emconf-wrap');
         if ($configuration['value'] !== null) {
@@ -171,7 +170,7 @@ class TypoScriptConstantsViewHelper extends AbstractTagBasedViewHelper
     protected function renderOptionSelect(array $configuration): string
     {
         $this->tag->setTagName('select');
-        $this->tag->addAttribute('id', 'em-' . $configuration['name']);
+        $this->addIdAttribute($configuration);
         $this->tag->addAttribute('name', $this->getName($configuration));
         $this->tag->addAttribute('class', 'form-control');
         $optionValueArray = $configuration['generic'];
@@ -198,7 +197,7 @@ class TypoScriptConstantsViewHelper extends AbstractTagBasedViewHelper
     {
         $this->tag->setTagName('input');
         $this->tag->addAttribute('type', 'number');
-        $this->tag->addAttribute('id', 'em-' . $configuration['name']);
+        $this->addIdAttribute($configuration);
         $this->tag->addAttribute('name', $this->getName($configuration));
         $this->tag->addAttribute('class', 'form-control');
         $this->tag->addAttribute('min', '0');
@@ -218,7 +217,7 @@ class TypoScriptConstantsViewHelper extends AbstractTagBasedViewHelper
     {
         $this->tag->setTagName('input');
         $this->tag->addAttribute('type', 'number');
-        $this->tag->addAttribute('id', 'em-' . $configuration['name']);
+        $this->addIdAttribute($configuration);
         $this->tag->addAttribute('name', $this->getName($configuration));
         $this->tag->addAttribute('class', 'form-control');
         if ($configuration['value'] !== null) {
@@ -237,7 +236,7 @@ class TypoScriptConstantsViewHelper extends AbstractTagBasedViewHelper
     {
         $this->tag->setTagName('input');
         $this->tag->addAttribute('type', 'text');
-        $this->tag->addAttribute('id', 'em-' . $configuration['name']);
+        $this->addIdAttribute($configuration);
         $this->tag->addAttribute('name', $this->getName($configuration));
         $this->tag->addAttribute('class', 'form-control');
         if ($configuration['value'] !== null) {
@@ -268,7 +267,7 @@ class TypoScriptConstantsViewHelper extends AbstractTagBasedViewHelper
         $this->tag->addAttribute('type', 'checkbox');
         $this->tag->addAttribute('name', $this->getName($configuration));
         $this->tag->addAttribute('value', 1);
-        $this->tag->addAttribute('id', 'em-' . $configuration['name']);
+        $this->addIdAttribute($configuration);
         if ($configuration['value'] == 1) {
             $this->tag->addAttribute('checked', 'checked');
         }
@@ -313,8 +312,11 @@ class TypoScriptConstantsViewHelper extends AbstractTagBasedViewHelper
     protected function renderHiddenFieldForEmptyValue(array $configuration): string
     {
         $hiddenFieldNames = [];
-        if ($this->viewHelperVariableContainer->exists(FormViewHelper::class, 'renderedHiddenFields')) {
-            $hiddenFieldNames = $this->viewHelperVariableContainer->get(FormViewHelper::class, 'renderedHiddenFields');
+
+        // check for already set hidden field within current extension
+        $variableKey = 'renderedHiddenFields-' . $configuration['extensionKey'];
+        if ($this->viewHelperVariableContainer->exists(FormViewHelper::class, $variableKey)) {
+            $hiddenFieldNames = $this->viewHelperVariableContainer->get(FormViewHelper::class, $variableKey);
         }
         $fieldName = $this->getName($configuration);
         if (substr($fieldName, -2) === '[]') {
@@ -322,7 +324,7 @@ class TypoScriptConstantsViewHelper extends AbstractTagBasedViewHelper
         }
         if (!in_array($fieldName, $hiddenFieldNames)) {
             $hiddenFieldNames[] = $fieldName;
-            $this->viewHelperVariableContainer->addOrUpdate(FormViewHelper::class, 'renderedHiddenFields', $hiddenFieldNames);
+            $this->viewHelperVariableContainer->addOrUpdate(FormViewHelper::class, $variableKey, $hiddenFieldNames);
             return '<input type="hidden" name="' . htmlspecialchars($fieldName) . '" value="0" />';
         }
         return '';
@@ -335,4 +337,17 @@ class TypoScriptConstantsViewHelper extends AbstractTagBasedViewHelper
     {
         return $GLOBALS['LANG'];
     }
+
+    /**
+     * Build and add id-attribute from $configuration
+     *
+     * @param array $configuration
+     */
+    protected function addIdAttribute(array $configuration): void
+    {
+        $this->tag->addAttribute(
+            'id',
+            'em-' . $configuration['extensionKey'] . '-' . $this->getName($configuration)
+        );
+    }
 }
index 4730ae7..2777d3f 100644 (file)
@@ -34,7 +34,7 @@
                                                     <h2 class="h4 form-section-headline">{configurationItem.subcat_label}</h2>
                                                 </f:if>
                                                 <div class="form-group form-group-dashed">
-                                                    <label for="em-{configurationItem.name}">
+                                                    <label for="em-{configurationItem.extensionKey}-{configurationItem.name}">
                                                         {configurationItem.labels.0}
                                                     </label>
                                                     <p>