Skip to content

Commit

Permalink
[BUGFIX] Implement multiple itemsProcFunc support
Browse files Browse the repository at this point in the history
  • Loading branch information
NamelessCoder committed Aug 5, 2023
1 parent 8b05036 commit fcc9932
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 4 deletions.
44 changes: 44 additions & 0 deletions Classes/Integration/MultipleItemsProcFunc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
namespace FluidTYPO3\Flux\Integration;

/*
* This file is part of the FluidTYPO3/Flux project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/

use TYPO3\CMS\Backend\Form\FormDataProviderInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class MultipleItemsProcFunc
{
public static function register(string $table, string $field, ?string $additionalFunction = null): void
{
$existingFunction = $GLOBALS['TCA'][$table]['columns'][$field]['config']['itemsProcFunc'] ?? null;
$newFunction = static::class . '->execute';

$GLOBALS['TCA'][$table]['multipleItemsProcessingFunctions'][$field] = array_values(
array_filter(
array_merge(
$GLOBALS['TCA'][$table]['multipleItemsProcessingFunctions'][$field] ?? [],
[
$existingFunction !== $newFunction ? $existingFunction : null,
$additionalFunction,
]
)
)
);
$GLOBALS['TCA'][$table]['columns'][$field]['config']['itemsProcFunc'] = $newFunction;
}

public function execute(array &$parameters, FormDataProviderInterface $formDataProvider): void
{
$table = $parameters['table'];
$field = $parameters['field'];
$processors = $GLOBALS['TCA'][$table]['multipleItemsProcessingFunctions'][$field] ?? [];
foreach (array_filter($processors) as $functionReference) {
GeneralUtility::callUserFunction($functionReference, $parameters, $formDataProvider);
}
}
}
14 changes: 12 additions & 2 deletions Configuration/TCA/Overrides/pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'itemsProcFunc' => 'FluidTYPO3\Flux\Backend\PageLayoutDataProvider->addItems',
'fieldWizard' => [
'selectIcons' => [
'disabled' => false
Expand All @@ -27,7 +26,6 @@
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'itemsProcFunc' => 'FluidTYPO3\Flux\Backend\PageLayoutDataProvider->addItems',
'fieldWizard' => [
'selectIcons' => [
'disabled' => false
Expand Down Expand Up @@ -57,6 +55,18 @@
],
]);

\FluidTYPO3\Flux\Integration\MultipleItemsProcFunc::register(
'pages',
'tx_fed_page_controller_action',
\FluidTYPO3\Flux\Backend\PageLayoutDataProvider::class . '->addItems'
);

\FluidTYPO3\Flux\Integration\MultipleItemsProcFunc::register(
'pages',
'tx_fed_page_controller_action_sub',
\FluidTYPO3\Flux\Backend\PageLayoutDataProvider::class . '->addItems'
);

$userFunctionsClass = new \FluidTYPO3\Flux\Integration\FormEngine\UserFunctions();
if (is_callable([$userFunctionsClass , 'fluxFormFieldDisplayCondition'])) {

Expand Down
8 changes: 6 additions & 2 deletions Configuration/TCA/Overrides/tt_content.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<?php

(function () {
$GLOBALS['TCA']['tt_content']['columns']['colPos']['config']['itemsProcFunc'] =
\FluidTYPO3\Flux\Integration\Overrides\BackendLayoutView::class . '->colPosListItemProcFunc';
\FluidTYPO3\Flux\Integration\MultipleItemsProcFunc::register(
'tt_content',
'colPos',
\FluidTYPO3\Flux\Integration\Overrides\BackendLayoutView::class . '->colPosListItemProcFunc'
);

$GLOBALS['TCA']['tt_content']['columns']['pi_flexform']['label'] = 'LLL:EXT:flux/Resources/Private/Language/locallang.xlf:tt_content.pi_flexform';

if (\FluidTYPO3\Flux\Utility\ExtensionConfigurationUtility::getOption(\FluidTYPO3\Flux\Utility\ExtensionConfigurationUtility::OPTION_FLEXFORM_TO_IRRE)) {
Expand Down
45 changes: 45 additions & 0 deletions Tests/Unit/Integration/MultipleItemsProcFuncTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
namespace FluidTYPO3\Flux\Tests\Unit\Integration;

/*
* This file is part of the FluidTYPO3/Flux project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/

use FluidTYPO3\Flux\Integration\MultipleItemsProcFunc;
use FluidTYPO3\Flux\Tests\Unit\AbstractTestCase;
use TYPO3\CMS\Backend\Form\FormDataProviderInterface;

class MultipleItemsProcFuncTest extends AbstractTestCase
{
private static $executed = false;

public function testRegistersFunction(): void
{
MultipleItemsProcFunc::register('table', 'field', static::class . '->dummyFunction');
self::assertSame(
MultipleItemsProcFunc::class . '->execute',
$GLOBALS['TCA']['table']['columns']['field']['config']['itemsProcFunc']
);
self::assertSame(
[static::class . '->dummyFunction'],
$GLOBALS['TCA']['table']['multipleItemsProcessingFunctions']['field']
);
}

public function testExecutesFunction(): void
{
$provider = $this->getMockBuilder(FormDataProviderInterface::class)->getMockForAbstractClass();
MultipleItemsProcFunc::register('table', 'field', static::class . '->dummyFunction');
$parameters = ['table' => 'table', 'field' => 'field'];
(new MultipleItemsProcFunc())->execute($parameters, $provider);
self::assertTrue(static::$executed);
}

public function dummyFunction(): void
{
static::$executed = true;
}
}

0 comments on commit fcc9932

Please sign in to comment.