Skip to content

Commit

Permalink
[BUGFIX] Proper styleguide data generator MM fields
Browse files Browse the repository at this point in the history
Patch for #102279 to auto-create DB select fields
reveals a bug in the styleguide data generator which
tries to create (partially empty) strings for the
"parent count" fields when select is configured with
MM.
The patch adapts the generator logic a bit to create
better values in those cases.

Resolves: #102704
Related: #102279
Releases: main
Change-Id: I236e1c6d5c1ce8abfa1e84fc35b6aa6c2765d762
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/82263
Tested-by: core-ci <typo3@b13.com>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Stefan Bürk <stefan@buerk.tech>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Stefan Bürk <stefan@buerk.tech>
  • Loading branch information
lolli42 committed Dec 20, 2023
1 parent 8b7acb3 commit c5a6f58
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@

namespace TYPO3\CMS\Styleguide\TcaDataGenerator\FieldGenerator;

use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Styleguide\TcaDataGenerator\FieldGeneratorInterface;
use TYPO3\CMS\Styleguide\TcaDataGenerator\RecordFinder;

/**
* Generate data for type=select fields
Expand All @@ -28,9 +26,6 @@
*/
final class TypeSelectRenderTypeSelectTree extends AbstractFieldGenerator implements FieldGeneratorInterface
{
/**
* @var array General match if type=select
*/
protected $matchArray = [
'fieldConfig' => [
'config' => [
Expand All @@ -41,32 +36,9 @@ final class TypeSelectRenderTypeSelectTree extends AbstractFieldGenerator implem
],
];

/**
* Returns the generated value to be inserted into DB for this field
*
* @param array $data
* @return string
*/
public function generate(array $data): string
{
/** @var RecordFinder $recordFinder */
$recordFinder = GeneralUtility::makeInstance(RecordFinder::class);
$uidOfStyleguideRootPage = $recordFinder->findPidOfMainTableRecord('tx_styleguide');
$uidOfElementsBasicPage = $recordFinder->findPidOfMainTableRecord('tx_styleguide_elements_basic');
$uidOfElementsGroupPage = $recordFinder->findPidOfMainTableRecord('tx_styleguide_elements_group');
$result = [];
// Don't add first page if not selectable
if (!isset($data['fieldConfig']['config']['treeConfig']['appearance']['nonSelectableLevels'])) {
$result[] = $uidOfStyleguideRootPage;
}
// Don't add sub pages if maxlevels is set
if (!isset($data['fieldConfig']['config']['treeConfig']['appearance']['maxLevels'])
|| (isset($data['fieldConfig']['config']['treeConfig']['appearance']['maxLevels'])
&& $data['fieldConfig']['config']['treeConfig']['appearance']['maxLevels'] > 1)
) {
$result[] = $uidOfElementsBasicPage;
$result[] = $uidOfElementsGroupPage;
}
return implode(',', $result);
// "Parent count" field - just use zero as string here.
return '0';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,27 @@

namespace TYPO3\CMS\Styleguide\TcaDataGenerator\FieldGenerator;

use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Styleguide\TcaDataGenerator\FieldGeneratorInterface;
use TYPO3\CMS\Styleguide\TcaDataGenerator\RecordFinder;

/**
* Generate data for type=select fields
* Generate data for type=select fields with foreign_table=tx_styleguide_staticdata and MM
*
* @internal
*/
final class TypeSelectRenderTypeMultipleForeignTableStaticData extends AbstractFieldGenerator implements FieldGeneratorInterface
final class TypeSelectStaticData extends AbstractFieldGenerator implements FieldGeneratorInterface
{
/**
* @var array General match if type=select
*/
protected $matchArray = [
'fieldConfig' => [
'config' => [
'type' => 'select',
'renderType' => 'selectMultipleSideBySide',
'foreign_table' => 'tx_styleguide_staticdata',
],
],
];

/**
* Returns the generated value to be inserted into DB for this field
*
* @param array $data
* @return string
*/
public function generate(array $data): string
{
/** @var RecordFinder $recordFinder */
$recordFinder = GeneralUtility::makeInstance(RecordFinder::class);
$staticDataRecords = $recordFinder->findUidsOfStaticdata();
// Select first two
return implode(',', array_slice($staticDataRecords, 0, 2));
// "Parent count" field - just use zero as string here.
return '0';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ final class FieldGeneratorResolver
// type=select
FieldGenerator\TypeSelectRenderTypeSingleForeignTable::class,
FieldGenerator\TypeSelectRenderTypeSingleForeignTableForType::class,
FieldGenerator\TypeSelectRenderTypeMultipleForeignTableStaticData::class,
FieldGenerator\TypeSelectRenderTypeSelectTree::class,
FieldGenerator\TypeSelectStaticData::class,
FieldGenerator\TypeSelect::class,

FieldGenerator\TypeInlineFalSelectSingle12Foreign::class,
Expand Down

0 comments on commit c5a6f58

Please sign in to comment.