forked from FluidTYPO3/flux
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUGFIX] Implement multiple itemsProcFunc support
Close: FluidTYPO3#2063
- Loading branch information
1 parent
8b05036
commit fcc9932
Showing
4 changed files
with
107 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |