[BUGFIX] TCA type="select", renderMode="tree", maxitems=1 doesn't work
authorMarco Huber <mail@marco-huber.de>
Thu, 17 Mar 2011 12:53:13 +0000 (13:53 +0100)
committerSteffen Ritter <info@rs-websystems.de>
Sat, 19 Mar 2011 17:29:23 +0000 (18:29 +0100)
commit290529a75647fe2bf6847638763e50348631e906
tree3fd0cb557af5d841c8824c98315dc503e20b5ab2
parentdda28123403d297ef4cf9b57610ee2e694ec64a9
[BUGFIX] TCA type="select", renderMode="tree", maxitems=1 doesn't work

Description
Problem:
I want to use the new TCA tree, but when I configure 1 as maxitems I
can't select a tree node.

This happens, because this.countSelectedNodes in
t3lib\js\extjs\tree\tree.js is 1 even when I create a new record.
And this.countSelectedNodes is 1 because $valueArray in
t3lib\tceforms\class.t3lib_tceforms_tree.php in the function
renderField always has at least one entry.

$valueArray is created by exploding $PA['itemFormElValue']. In fresh
records $PA['itemFormElValue'] is 0 and not NULL (or not set) and
has no other effects. But $valueArray has an entry and that's why
count($valueArray) is 1 and then this.countSelectedNodes is also 1.

To reproduce this issue you can use this TCA (Thanks to Steffen:
http://lists.typo3.org/pipermail/typo3-team-core/2010-November/044931.html):
$GLOBALS['TCA']['pages']['columns']['fe_group']['config']
['renderMode'] = 'tree';
$GLOBALS['TCA']['pages']['columns']['fe_group']['config']['maxitems'] = 1;
$GLOBALS['TCA']['pages']['columns']['fe_group']['config']['treeConfig']
= array(
     'parentField' => 'subgroup',
     'appearance' => array(
         'expandAll' => TRUE,
         'showHeader' => TRUE,
     )
);

Solution:
To fix this issue $PA['itemFormElValue'] should be only exploded if it's
not 0. Like I wrote before, this is done in
t3lib\tceforms\class.t3lib_tceforms_tree.php and fixed in the appended
patch.

Fixing this issue causes a little follow up in t3lib\js\extjs\tree\tree.js.
This is also fixed in the patch.

Change-Id: I5d23ea1d63b1107925e265392f4d13f4db3d1063
Resolves: #M17976
Reviewed-on: http://review.typo3.org/1188
Reviewed-by: Moritz <moemos@gmail.com>
Tested-by: Moritz <moemos@gmail.com>
Reviewed-by: Steffen Ritter <info@rs-websystems.de>
Tested-by: Steffen Ritter <info@rs-websystems.de>
t3lib/js/extjs/tree/tree.js
t3lib/tceforms/class.t3lib_tceforms_tree.php