[FEATURE] FormEngine: Possibility to add icons via pageTSconfig 67/22067/6
authorBenjamin Mack <benni@typo3.org>
Sat, 6 Jul 2013 20:48:01 +0000 (22:48 +0200)
committerGeorg Ringer <georg.ringer@gmail.com>
Wed, 10 Dec 2014 20:16:07 +0000 (21:16 +0100)
If someone adds a new value/label pair for a select field in
TCEforms/FormEngine, it is not possible to also add an icon to
the new option.
Alternatively, existing values can be changed through the new
"altIcons" property that acts like the "altLabels" property.

The patch adds another subelement for TSconfig to also add an
icon, as well as a new property.

TCEFORM.pages.doktype.addItems {
13 = My Label
13.icon = sysext/t3skin/icons/gfx/i/pages.gif
}
TCEFORM.pages.doktype.altIcons {
123 = EXT:myext/icon.gif
}

The icon path must be relative to the typo3/ directory.

Resolves: #35891
Releases: master
Documentation: #49752
Change-Id: Ic835b1fe350144bc3498eab9a19857e3f558088d
Reviewed-on: http://review.typo3.org/22067
Reviewed-by: Alessandro Bellafronte <alessandro@4eyes.ch>
Reviewed-by: Christoph Dörfel <christoph.doerfel@gmail.com>
Reviewed-by: Michel Georgy <michel@4eyes.ch>
Tested-by: Susanne Moog <typo3@susannemoog.de>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
typo3/sysext/backend/Classes/Form/Element/InlineElement.php
typo3/sysext/backend/Classes/Form/Element/SelectElement.php
typo3/sysext/backend/Classes/Form/FlexFormsHelper.php
typo3/sysext/backend/Classes/Form/FormEngine.php
typo3/sysext/core/Documentation/Changelog/master/Feature-35891-AddTCAItemsWithIconsViaPageTSConfig.rst [new file with mode: 0644]
typo3/sysext/t3editor/res/jslib/parse_typoscript/tokenizetyposcript.js

index 84b11e6..196dcf3 100644 (file)
@@ -1659,8 +1659,13 @@ class InlineElement {
                                $authModeDeny = $config['form_type'] == 'select' && $config['authMode'] && !$GLOBALS['BE_USER']->checkAuthMode($table, $field, $p[1], $config['authMode']);
                                if (in_array($p[1], $removeItems) || $languageDeny || $authModeDeny) {
                                        unset($selItems[$tk]);
-                               } elseif (isset($PA['fieldTSConfig']['altLabels.'][$p[1]])) {
-                                       $selItems[$tk][0] = htmlspecialchars($this->fObj->sL($PA['fieldTSConfig']['altLabels.'][$p[1]]));
+                               } else {
+                                       if (isset($PA['fieldTSConfig']['altLabels.'][$p[1]])) {
+                                               $selItems[$tk][0] = htmlspecialchars($this->fObj->sL($PA['fieldTSConfig']['altLabels.'][$p[1]]));
+                                       }
+                                       if (isset($PA['fieldTSConfig']['altIcons.'][$p[1]])) {
+                                               $selItems[$tk][2] = $PA['fieldTSConfig']['altIcons.'][$p[1]];
+                                       }
                                }
                                // Removing doktypes with no access:
                                if (($table === 'pages' || $table === 'pages_language_overlay') && $field === 'doktype') {
index 24dc62d..769c2e6 100644 (file)
@@ -136,8 +136,13 @@ class SelectElement extends AbstractFormElement {
                                && !$this->getBackendUserAuthentication()->checkAuthMode($table, $field, $evalValue, $config['authMode']);
                        if ($isRemoved && !$PA['fieldTSConfig']['disableNoMatchingValueElement'] && !$config['disableNoMatchingValueElement']) {
                                $tvP[1] = rawurlencode(@sprintf($nMV_label, $evalValue));
-                       } elseif (isset($PA['fieldTSConfig']['altLabels.'][$evalValue])) {
-                               $tvP[1] = rawurlencode($this->formEngine->sL($PA['fieldTSConfig']['altLabels.'][$evalValue]));
+                       } else {
+                               if (isset($PA['fieldTSConfig']['altLabels.'][$evalValue])) {
+                                       $tvP[1] = rawurlencode($this->formEngine->sL($PA['fieldTSConfig']['altLabels.'][$evalValue]));
+                               }
+                               if (isset($PA['fieldTSConfig']['altIcons.'][$evalValue])) {
+                                       $tvP[2] = $PA['fieldTSConfig']['altIcons.'][$evalValue];
+                               }
                        }
                        if ($tvP[1] == '') {
                                // Case: flexform, default values supplied, no label provided (bug #9795)
index acefc33..e001b67 100644 (file)
@@ -169,10 +169,12 @@ class FlexFormsHelper extends \TYPO3\CMS\Backend\Form\FormEngine {
                        $removeItems = !empty($fieldConf['removeItems']) ? GeneralUtility::trimExplode(',', $fieldConf['removeItems'], TRUE) : array();
                        $keepItems = !empty($fieldConf['keepItems']) ? GeneralUtility::trimExplode(',', $fieldConf['keepItems'], TRUE) : array();
                        $renameItems = !empty($fieldConf['altLabels']) && is_array($fieldConf['altLabels']) ? $fieldConf['altLabels'] : array();
+                       $changeIcons = !empty($fieldConf['altIcons']) && is_array($fieldConf['altIcons']) ? $fieldConf['altIcons'] : array();
                        $addItems = !empty($fieldConf['addItems']) && is_array($fieldConf['addItems']) ? $fieldConf['addItems'] : array();
                        unset($fieldConf['removeItems']);
                        unset($fieldConf['keepItems']);
                        unset($fieldConf['altLabels']);
+                       unset($fieldConf['altIcons']);
                        unset($fieldConf['addItems']);
                        // Manipulate field
                        if (!empty($field['TCEforms']) && is_array($field['TCEforms'])) {
@@ -205,8 +207,8 @@ class FlexFormsHelper extends \TYPO3\CMS\Backend\Form\FormEngine {
                        foreach ($this->removeSelectConfig as $option) {
                                unset($sheet[$fieldName]['TCEforms']['config'][$option]);
                        }
-                       // Rename and remove items in select
-                       if ((!empty($removeItems) || !empty($renameItems)) && !empty($selItems) && is_array($selItems)) {
+                       // Rename and remove items or change item icon in select
+                       if ((!empty($removeItems) || !empty($renameItems) || !empty($changeIcons)) && !empty($selItems) && is_array($selItems)) {
                                foreach ($selItems as $itemKey => $itemConf) {
                                        // Option has no key, no manipulation possible
                                        if (!isset($itemConf[1])) {
@@ -226,6 +228,13 @@ class FlexFormsHelper extends \TYPO3\CMS\Backend\Form\FormEngine {
                                                        unset($renameItems[$renameKey]);
                                                }
                                        }
+                                       // Change icon
+                                       foreach ($changeIcons as $iconKey => $iconValue) {
+                                               if (strcasecmp($iconKey, $itemConf[1]) == 0) {
+                                                       $selItems[$itemKey][2] = $iconValue;
+                                                       unset($changeIcons[$iconKey]);
+                                               }
+                                       }
                                }
                        }
                        $sheet[$fieldName]['TCEforms']['config']['items'] = $selItems;
index 54be028..7b54070 100644 (file)
@@ -3120,7 +3120,10 @@ class FormEngine {
        }
 
        /**
-        * Merges items into an item-array
+        * Merges items into an item-array, optionally with an icon
+        * example:
+        * TCEFORM.pages.doktype.addItems.13 = My Label
+        * TCEFORM.pages.doktype.addItems.13.icon = EXT:t3skin/icons/gfx/i/pages.gif
         *
         * @param array $items The existing item array
         * @param array $iArray An array of items to add. NOTICE: The keys are mapped to values, and the values and mapped to be labels. No possibility of adding an icon.
@@ -3129,7 +3132,18 @@ class FormEngine {
        public function addItems($items, $iArray) {
                if (is_array($iArray)) {
                        foreach ($iArray as $value => $label) {
-                               $items[] = array($this->sl($label), $value);
+                               // if the label is an array (that means it is a subelement
+                               // like "34.icon = mylabel.png", skip it (see its usage below)
+                               if (is_array($label)) {
+                                       continue;
+                               }
+                               // check if the value "34 = mylabel" also has a "34.icon = myimage.png"
+                               if (isset($iArray[$value . '.']) && $iArray[$value . '.']['icon']) {
+                                       $icon = $iArray[$value . '.']['icon'];
+                               } else {
+                                       $icon = '';
+                               }
+                               $items[] = array($this->sL($label), $value, $icon);
                        }
                }
                return $items;
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-35891-AddTCAItemsWithIconsViaPageTSConfig.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-35891-AddTCAItemsWithIconsViaPageTSConfig.rst
new file mode 100644 (file)
index 0000000..f9794d9
--- /dev/null
@@ -0,0 +1,22 @@
+=======================================================================
+Feature: #35891 - FormEngine: Possibility to add icons via PageTSconfig
+=======================================================================
+
+Description
+===========
+
+The possibility to add a new value/label pair for a select field in FormEngine is given via the pageTSconfig option
+"addItems". Now, it is also possible to give the items an icon. Either with the .icon subproperty or with the
+separate option "altIcons".
+
+.. code-block:: typoscript
+
+       TCEFORM.pages.doktype.addItems {
+               13 = My Label
+               13.icon = EXT:t3skin/icons/gfx/i/pages.gif
+       }
+       TCEFORM.pages.doktype.altIcons {
+               123 = EXT:myext/icon.gif
+       }
+
+If the path is not prefixed with "EXT:" it needs to be relative to the typo3/ directory.
\ No newline at end of file
index 66e658c..eef79ec 100644 (file)
@@ -131,6 +131,7 @@ var typoscriptWords = {
        'alternativeTempPath': 'reserved',
        'altImgResource': 'reserved',
        'altLabels': 'reserved',
+       'altIcons': 'reserved',
        'altTarget': 'reserved',
        'altText': 'reserved',
        'altUrl': 'reserved',
@@ -1451,6 +1452,7 @@ var typoscriptWords = {
        'alternativeTempPath': 'reserved',
        'altImgResource': 'reserved',
        'altLabels': 'reserved',
+       'altIcons': 'reserved',
        'altTarget': 'reserved',
        'altText': 'reserved',
        'altUrl': 'reserved',