Commit 8fad94bc authored by Frank Nägler's avatar Frank Nägler Committed by Christian Kuhn
Browse files

[BUGFIX] selectTree pageTsConfig addItems

Adding items for type selectTree with pageTsConfig does not
work as documented. The TCA tree needs multi-root handling
to handle that. Additionally, some slight changes in the order
of elements when items are calculated are needed.

Resolves: #78628
Releases: master
Change-Id: Iecf0225c0eeaab8ea661997cad26e68d255d8460
Reviewed-on: https://review.typo3.org/50565

Tested-by: default avatarTYPO3com <no-reply@typo3.com>
Reviewed-by: Markus Klein's avatarMarkus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein's avatarMarkus Klein <markus.klein@typo3.org>
Reviewed-by: Wouter Wolters's avatarWouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
parent a947f4c2
......@@ -69,12 +69,11 @@ class SelectTreeElement extends AbstractFormElement
$expanded = !empty($appearance['expandAll']);
$showHeader = !empty($appearance['showHeader']);
if (isset($config['size']) && (int)$config['size'] > 0) {
$height = min(max(count($config['items']), $this->minItemsToShow), (int)$config['size']);
$height = max($this->minItemsToShow, (int)$config['size']);
} else {
$height = $this->itemsToShow;
}
$heightInPx = $height * $this->itemHeight;
$treeWrapperId = 'tree_' . $formElementId;
$flexFormFieldName = !empty($parameterArray['fieldConf']['flexFormFieldName']) ? htmlspecialchars($parameterArray['fieldConf']['flexFormFieldName']) : '';
......@@ -95,7 +94,7 @@ class SelectTreeElement extends AbstractFormElement
$html[] = ' data-tree-show-toolbar="' . $showHeader . '"';
$html[] = ' name="' . htmlspecialchars($parameterArray['itemFormElName']) . '"';
$html[] = ' id="treeinput' . $formElementId . '"';
$html[] = ' value="' . htmlspecialchars(implode(',', $config['treeData']['selectedNodes'])) . '"';
$html[] = ' value=""';
$html[] = ' />';
$html[] = '</div>';
$html[] = '<div id="' . $treeWrapperId . '" class="svg-tree-wrapper" style="height: ' . $heightInPx . 'px;"></div>';
......
......@@ -24,6 +24,7 @@ use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Database\Query\QueryHelper;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Database\RelationHandler;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Imaging\IconRegistry;
use TYPO3\CMS\Core\Messaging\FlashMessage;
......@@ -117,6 +118,9 @@ abstract class AbstractItemProvider
protected function addItemsFromPageTsConfig(array $result, $fieldName, array $items)
{
$table = $result['tableName'];
$iconRegistry = GeneralUtility::makeInstance(IconRegistry::class);
$iconFactory = GeneralUtility::makeInstance(IconFactory::class);
if (!empty($result['pageTsConfig']['TCEFORM.'][$table . '.'][$fieldName . '.']['addItems.'])
&& is_array($result['pageTsConfig']['TCEFORM.'][$table . '.'][$fieldName . '.']['addItems.'])
) {
......@@ -132,7 +136,25 @@ abstract class AbstractItemProvider
&& is_array($addItemsArray[$value . '.'])
&& !empty($addItemsArray[$value . '.']['icon'])
) {
$icon = $addItemsArray[$value . '.']['icon'];
$iconIdentifier = $addItemsArray[$value . '.']['icon'];
if (!$iconRegistry->isRegistered($iconIdentifier)) {
GeneralUtility::deprecationLog(
'Using a file path for icon in pageTsConfig addItems is deprecated.' .
'Use a registered iconIdentifier instead'
);
$iconPath = GeneralUtility::getFileAbsFileName($iconIdentifier);
if ($iconPath !== '') {
$iconIdentifier = md5($iconPath);
$iconRegistry->registerIcon(
$iconIdentifier,
$iconRegistry->detectIconProvider($iconPath),
[
'source' => $iconPath
]
);
}
}
$icon = $iconFactory->getIcon($iconIdentifier, Icon::SIZE_SMALL)->getMarkup('inline');
}
$items[] = [$label, $value, $icon];
}
......
......@@ -49,15 +49,16 @@ class TcaSelectTreeItems extends AbstractItemProvider implements FormDataProvide
$fieldConfig['config']['items'] = $this->sanitizeItemArray($fieldConfig['config']['items'], $table, $fieldName);
$fieldConfig['config']['maxitems'] = $this->sanitizeMaxItems($fieldConfig['config']['maxitems']);
$pageTsConfigAddItems = $this->addItemsFromPageTsConfig($result, $fieldName, []);
$fieldConfig['config']['items'] = $this->addItemsFromSpecial($result, $fieldName, $fieldConfig['config']['items']);
$fieldConfig['config']['items'] = $this->addItemsFromFolder($result, $fieldName, $fieldConfig['config']['items']);
$staticItems = $fieldConfig['config']['items'];
$staticItems = $fieldConfig['config']['items'] + $pageTsConfigAddItems;
$fieldConfig['config']['items'] = $this->addItemsFromForeignTable($result, $fieldName, $fieldConfig['config']['items']);
$dynamicItems = array_diff_key($fieldConfig['config']['items'], $staticItems);
$fieldConfig['config']['items'] = $this->removeItemsByKeepItemsPageTsConfig($result, $fieldName, $fieldConfig['config']['items']);
$fieldConfig['config']['items'] = $this->addItemsFromPageTsConfig($result, $fieldName, $fieldConfig['config']['items']);
$fieldConfig['config']['items'] = $pageTsConfigAddItems + $fieldConfig['config']['items'];
$fieldConfig['config']['items'] = $this->removeItemsByRemoveItemsPageTsConfig($result, $fieldName, $fieldConfig['config']['items']);
$fieldConfig['config']['items'] = $this->removeItemsByUserLanguageFieldRestriction($result, $fieldName, $fieldConfig['config']['items']);
......@@ -178,7 +179,7 @@ class TcaSelectTreeItems extends AbstractItemProvider implements FormDataProvide
'selectable' => true,
'leaf' => true,
'checked' => in_array($item[1], $selectedNodes),
'icon' => $item[3]
'icon' => $item[2]
];
}
......
......@@ -153,6 +153,11 @@ define(['d3', 'TYPO3/CMS/Backend/FormEngine/Element/SvgTree'], function (d3, Svg
node.indeterminate = false;
});
this.calculateIndeterminate(this.rootNode);
// Initialise "value" attribute of input field after load and revalidate form engine fields
this.saveCheckboxes(this.rootNode);
if (typeof TYPO3.FormEngine.Validation !== 'undefined' && typeof TYPO3.FormEngine.Validation.validate === 'function') {
TYPO3.FormEngine.Validation.validate();
}
};
/**
......
......@@ -194,10 +194,46 @@ define(['jquery', 'd3'], function ($, d3) {
return;
}
if (Array.isArray(json)) {
//little hack, so we can use json structure prepared by ExtJsJsonTreeRenderer
json = json[0];
if (json.length > 1) {
// If tree comes with multiple root nodes, add them to a new root
var tmp = {
checked: undefined,
children: [],
expandable: true,
expanded: true,
iconTag: null,
id: '',
identifier: 'root',
leaf: false,
name: '',
overlayIcon: '',
text: '',
uid: ''
};
for (var i = 0; i < json.length; i++) {
var n = json[i];
if (typeof n.identifier === 'undefined') {
n.identifier = n.uid;
}
if (typeof n.name === 'undefined') {
n.name = n.text;
}
if (typeof n.expandable === 'undefined') {
n.expandable = true;
}
if (typeof n.expanded === 'undefined') {
n.expanded = true;
}
if (typeof n.icon !== 'undefined') {
n.iconTag = n.icon;
}
tmp.children.push(n);
}
json = tmp;
} else {
json = json[0];
}
}
var rootNode = d3.hierarchy(json);
d3.tree(rootNode);
......
......@@ -408,7 +408,7 @@ class CategoryRegistry implements SingletonInterface
'tablenames' => $tableName,
'fieldname' => $fieldName,
],
'size' => 50,
'size' => 20,
'maxitems' => 9999,
'treeConfig' => [
'parentField' => 'parent',
......
.. include:: ../../Includes.txt
==============================================================
Deprecation: #78628 - TCA tree pageTsConfig addItems icon path
==============================================================
See :issue:`78628`
Description
===========
When adding items to `TCA` `type="select"` fields with `pageTSConfig`, the syntax for icons has been changed:
Example to add an item with icon in pages to field category before:
.. code-block:: typoscript
# Add an item with text "staticFromPageTs" to field category in pages
TCEFORM.pages.category.addItems.12345 = staticFromPageTs
# Assign icon to the element
TCEFORM.pages.category.addItems.12345.icon = EXT:any_extension/Resources/Public/Icons/Smiley.png
The path has been deprecated and now accepts icon identifiers from the icon registry only:
.. code-block:: typoscript
# Add an item with text "staticFromPageTs" to field category in pages
TCEFORM.pages.category.addItems.12345 = staticFromPageTs
# Assign icon to the element
TCEFORM.pages.category.addItems.12345.icon = my-registered-icon
Impact
======
Using a file path syntax will trigger a deprecation log entry, but will work until TYPO3 v9.0.
Affected Installations
======================
Instances that use this PageTSConfig setting with a file path instead of an icon identifier.
Migration
=========
Register the icon within the :php:`IconRegistry` and use an icon identifier instead of the file path
.. index:: TSConfig, Backend, TCA
......@@ -1015,7 +1015,7 @@ return [
'renderType' => 'selectTree',
'foreign_table' => 'sys_category',
'foreign_table_where' => 'AND sys_category.sys_language_uid IN (0,-1) ORDER BY sys_category.title ASC',
'size' => 50,
'size' => 20,
'maxitems' => 9999,
'treeConfig' => [
'parentField' => 'parent',
......
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