Commit 0528f4fd authored by Benni Mack's avatar Benni Mack Committed by Georg Ringer
Browse files

[FEATURE] FormEngine: Possibility to add icons via pageTSconfig

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: default avatarAlessandro Bellafronte <alessandro@4eyes.ch>
Reviewed-by: default avatarChristoph Dörfel <christoph.doerfel@gmail.com>
Reviewed-by: default avatarMichel Georgy <michel@4eyes.ch>
Tested-by: default avatarSusanne Moog <typo3@susannemoog.de>
Reviewed-by: Georg Ringer's avatarGeorg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer's avatarGeorg Ringer <georg.ringer@gmail.com>
parent 437b3baf
......@@ -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') {
......
......@@ -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)
......
......@@ -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;
......
......@@ -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;
......
=======================================================================
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
......@@ -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',
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment