use TYPO3\CMS\Core\Messaging\FlashMessageService;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Service\DependencyOrderingService;
+use TYPO3\CMS\Core\Service\FlexFormService;
use TYPO3\CMS\Core\Type\Bitmask\Permission;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3\CMS\Core\Utility\StringUtility;
use TYPO3\CMS\Core\Versioning\VersionState;
-use TYPO3\CMS\Extbase\Service\FlexFormService;
use TYPO3\CMS\Fluid\View\StandaloneView;
use TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Resource\Index\FileIndexRepository;
+use TYPO3\CMS\Core\Service\FlexFormService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3\CMS\Core\Utility\PathUtility;
-use TYPO3\CMS\Extbase\Service\FlexFormService;
use TYPO3\CMS\Extbase\SignalSlot\Dispatcher;
// @todo implement constructor-level caching
--- /dev/null
+<?php
+namespace TYPO3\CMS\Core\Service;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+/**
+ * Utilities to process flexForms
+ */
+class FlexFormService implements \TYPO3\CMS\Core\SingletonInterface
+{
+ /**
+ * Parses the flexForm content and converts it to an array
+ * The resulting array will be multi-dimensional, as a value "bla.blubb"
+ * results in two levels, and a value "bla.blubb.bla" results in three levels.
+ *
+ * Note: multi-language flexForms are not supported yet
+ *
+ * @param string $flexFormContent flexForm xml string
+ * @param string $languagePointer language pointer used in the flexForm
+ * @param string $valuePointer value pointer used in the flexForm
+ * @return array the processed array
+ */
+ public function convertFlexFormContentToArray($flexFormContent, $languagePointer = 'lDEF', $valuePointer = 'vDEF')
+ {
+ $settings = [];
+ $flexFormArray = \TYPO3\CMS\Core\Utility\GeneralUtility::xml2array($flexFormContent);
+ $flexFormArray = $flexFormArray['data'] ?? [];
+ foreach (array_values($flexFormArray) as $languages) {
+ if (!is_array($languages[$languagePointer])) {
+ continue;
+ }
+ foreach ($languages[$languagePointer] as $valueKey => $valueDefinition) {
+ if (strpos($valueKey, '.') === false) {
+ $settings[$valueKey] = $this->walkFlexFormNode($valueDefinition, $valuePointer);
+ } else {
+ $valueKeyParts = explode('.', $valueKey);
+ $currentNode = &$settings;
+ foreach ($valueKeyParts as $valueKeyPart) {
+ $currentNode = &$currentNode[$valueKeyPart];
+ }
+ if (is_array($valueDefinition)) {
+ if (array_key_exists($valuePointer, $valueDefinition)) {
+ $currentNode = $valueDefinition[$valuePointer];
+ } else {
+ $currentNode = $this->walkFlexFormNode($valueDefinition, $valuePointer);
+ }
+ } else {
+ $currentNode = $valueDefinition;
+ }
+ }
+ }
+ }
+ return $settings;
+ }
+
+ /**
+ * Parses a flexForm node recursively and takes care of sections etc
+ *
+ * @param array $nodeArray The flexForm node to parse
+ * @param string $valuePointer The valuePointer to use for value retrieval
+ * @return array
+ */
+ public function walkFlexFormNode($nodeArray, $valuePointer = 'vDEF')
+ {
+ if (is_array($nodeArray)) {
+ $return = [];
+ foreach ($nodeArray as $nodeKey => $nodeValue) {
+ if ($nodeKey === $valuePointer) {
+ return $nodeValue;
+ }
+ if (in_array($nodeKey, ['el', '_arrayContainer'])) {
+ return $this->walkFlexFormNode($nodeValue, $valuePointer);
+ }
+ if ($nodeKey[0] === '_') {
+ continue;
+ }
+ if (strpos($nodeKey, '.')) {
+ $nodeKeyParts = explode('.', $nodeKey);
+ $currentNode = &$return;
+ $nodeKeyPartsCount = count($nodeKeyParts);
+ for ($i = 0; $i < $nodeKeyPartsCount - 1; $i++) {
+ $currentNode = &$currentNode[$nodeKeyParts[$i]];
+ }
+ $newNode = [next($nodeKeyParts) => $nodeValue];
+ $subVal = $this->walkFlexFormNode($newNode, $valuePointer);
+ $currentNode[key($subVal)] = current($subVal);
+ } elseif (is_array($nodeValue)) {
+ if (array_key_exists($valuePointer, $nodeValue)) {
+ $return[$nodeKey] = $nodeValue[$valuePointer];
+ } else {
+ $return[$nodeKey] = $this->walkFlexFormNode($nodeValue, $valuePointer);
+ }
+ } else {
+ $return[$nodeKey] = $nodeValue;
+ }
+ }
+ return $return;
+ }
+ return $nodeArray;
+ }
+}
--- /dev/null
+.. include:: ../../Includes.txt
+
+=======================================================================
+Deprecation: #85802 - Move FlexFormService from EXT:extbase to EXT:core
+=======================================================================
+
+See :issue:`85802`
+
+Description
+===========
+
+Move FlexFormService from EXT:extbase to EXT:core
+
+
+Impact
+======
+
+The PHP class :php:`TYPO3\CMS\Extbase\Service\FlexFormService` has been moved from the system
+extension `extbase` to `core`. The PHP class has been renamed to
+:php:`TYPO3\CMS\Core\Service\FlexFormService`.
+
+
+Affected Installations
+======================
+
+Any TYPO3 installation where this PHP class is in use within a TYPO3 extension.
+
+
+Migration
+=========
+
+Use the new namespace to reference the :php:`TYPO3\CMS\Core\Service\FlexFormService`
+
+.. index:: PHP-API, FullyScanned, ext:extbase
\ No newline at end of file
--- /dev/null
+<?php
+namespace TYPO3\CMS\Core\Tests\Unit\Service;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
+
+/**
+ * Test case
+ */
+class FlexFormServiceTest extends UnitTestCase
+{
+ /**
+ * @var bool Reset singletons created by subject
+ */
+ protected $resetSingletonInstances = true;
+
+ /**
+ * @test
+ */
+ public function convertFlexFormContentToArrayResolvesComplexArrayStructure()
+ {
+ $input = '<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
+<T3FlexForms>
+ <data>
+ <sheet index="sDEF">
+ <language index="lDEF">
+ <field index="settings.foo">
+ <value index="vDEF">Foo-Value</value>
+ </field>
+ <field index="settings.bar">
+ <el index="el">
+ <section index="1">
+ <itemType index="_arrayContainer">
+ <el>
+ <field index="baz">
+ <value index="vDEF">Baz1-Value</value>
+ </field>
+ <field index="bum">
+ <value index="vDEF">Bum1-Value</value>
+ </field>
+ <field index="dot.one">
+ <value index="vDEF">dot.one-Value</value>
+ </field>
+ <field index="dot.two">
+ <value index="vDEF">dot.two-Value</value>
+ </field>
+ </el>
+ </itemType>
+ <itemType index="_TOGGLE">0</itemType>
+ </section>
+ <section index="2">
+ <itemType index="_arrayContainer">
+ <el>
+ <field index="baz">
+ <value index="vDEF">Baz2-Value</value>
+ </field>
+ <field index="bum">
+ <value index="vDEF">Bum2-Value</value>
+ </field>
+ </el>
+ </itemType>
+ <itemType index="_TOGGLE">0</itemType>
+ </section>
+ </el>
+ </field>
+ </language>
+ </sheet>
+ </data>
+</T3FlexForms>';
+
+ $expected = [
+ 'settings' => [
+ 'foo' => 'Foo-Value',
+ 'bar' => [
+ 1 => [
+ 'baz' => 'Baz1-Value',
+ 'bum' => 'Bum1-Value',
+ 'dot' => [
+ 'one' => 'dot.one-Value',
+ 'two' => 'dot.two-Value',
+ ],
+ ],
+ 2 => [
+ 'baz' => 'Baz2-Value',
+ 'bum' => 'Bum2-Value'
+ ]
+ ]
+ ]
+ ];
+
+ // The subject calls xml2array statically, which calls getHash and setHash statically, which uses
+ // caches, those need to be mocked.
+ $cacheManagerMock = $this->createMock(\TYPO3\CMS\Core\Cache\CacheManager::class);
+ $cacheMock = $this->createMock(\TYPO3\CMS\Core\Cache\Frontend\FrontendInterface::class);
+ $cacheManagerMock->expects($this->any())->method('getCache')->will($this->returnValue($cacheMock));
+ GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Cache\CacheManager::class, $cacheManagerMock);
+
+ $flexFormService = $this->getMockBuilder(\TYPO3\CMS\Core\Service\FlexFormService::class)
+ ->setMethods(['dummy'])
+ ->disableOriginalConstructor()
+ ->getMock();
+ $convertedFlexFormArray = $flexFormService->convertFlexFormContentToArray($input);
+ $this->assertSame($expected, $convertedFlexFormArray);
+ }
+}
class FrontendConfigurationManager extends \TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager
{
/**
- * @var \TYPO3\CMS\Extbase\Service\FlexFormService
+ * @var \TYPO3\CMS\Core\Service\FlexFormService
*/
protected $flexFormService;
/**
- * @param \TYPO3\CMS\Extbase\Service\FlexFormService $flexFormService
+ * @param \TYPO3\CMS\Core\Service\FlexFormService $flexFormService
*/
- public function injectFlexFormService(\TYPO3\CMS\Extbase\Service\FlexFormService $flexFormService)
+ public function injectFlexFormService(\TYPO3\CMS\Core\Service\FlexFormService $flexFormService)
{
$this->flexFormService = $flexFormService;
}
+++ /dev/null
-<?php
-namespace TYPO3\CMS\Extbase\Service;
-
-/*
- * This file is part of the TYPO3 CMS project.
- *
- * It is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License, either version 2
- * of the License, or any later version.
- *
- * For the full copyright and license information, please read the
- * LICENSE.txt file that was distributed with this source code.
- *
- * The TYPO3 project - inspiring people to share!
- */
-
-/**
- * Utilities to process flexForms
- */
-class FlexFormService implements \TYPO3\CMS\Core\SingletonInterface
-{
- /**
- * Parses the flexForm content and converts it to an array
- * The resulting array will be multi-dimensional, as a value "bla.blubb"
- * results in two levels, and a value "bla.blubb.bla" results in three levels.
- *
- * Note: multi-language flexForms are not supported yet
- *
- * @param string $flexFormContent flexForm xml string
- * @param string $languagePointer language pointer used in the flexForm
- * @param string $valuePointer value pointer used in the flexForm
- * @return array the processed array
- */
- public function convertFlexFormContentToArray($flexFormContent, $languagePointer = 'lDEF', $valuePointer = 'vDEF')
- {
- $settings = [];
- $flexFormArray = \TYPO3\CMS\Core\Utility\GeneralUtility::xml2array($flexFormContent);
- $flexFormArray = $flexFormArray['data'] ?? [];
- foreach (array_values($flexFormArray) as $languages) {
- if (!is_array($languages[$languagePointer])) {
- continue;
- }
- foreach ($languages[$languagePointer] as $valueKey => $valueDefinition) {
- if (strpos($valueKey, '.') === false) {
- $settings[$valueKey] = $this->walkFlexFormNode($valueDefinition, $valuePointer);
- } else {
- $valueKeyParts = explode('.', $valueKey);
- $currentNode = &$settings;
- foreach ($valueKeyParts as $valueKeyPart) {
- $currentNode = &$currentNode[$valueKeyPart];
- }
- if (is_array($valueDefinition)) {
- if (array_key_exists($valuePointer, $valueDefinition)) {
- $currentNode = $valueDefinition[$valuePointer];
- } else {
- $currentNode = $this->walkFlexFormNode($valueDefinition, $valuePointer);
- }
- } else {
- $currentNode = $valueDefinition;
- }
- }
- }
- }
- return $settings;
- }
-
- /**
- * Parses a flexForm node recursively and takes care of sections etc
- *
- * @param array $nodeArray The flexForm node to parse
- * @param string $valuePointer The valuePointer to use for value retrieval
- * @return array
- */
- public function walkFlexFormNode($nodeArray, $valuePointer = 'vDEF')
- {
- if (is_array($nodeArray)) {
- $return = [];
- foreach ($nodeArray as $nodeKey => $nodeValue) {
- if ($nodeKey === $valuePointer) {
- return $nodeValue;
- }
- if (in_array($nodeKey, ['el', '_arrayContainer'])) {
- return $this->walkFlexFormNode($nodeValue, $valuePointer);
- }
- if ($nodeKey[0] === '_') {
- continue;
- }
- if (strpos($nodeKey, '.')) {
- $nodeKeyParts = explode('.', $nodeKey);
- $currentNode = &$return;
- $nodeKeyPartsCount = count($nodeKeyParts);
- for ($i = 0; $i < $nodeKeyPartsCount - 1; $i++) {
- $currentNode = &$currentNode[$nodeKeyParts[$i]];
- }
- $newNode = [next($nodeKeyParts) => $nodeValue];
- $subVal = $this->walkFlexFormNode($newNode, $valuePointer);
- $currentNode[key($subVal)] = current($subVal);
- } elseif (is_array($nodeValue)) {
- if (array_key_exists($valuePointer, $nodeValue)) {
- $return[$nodeKey] = $nodeValue[$valuePointer];
- } else {
- $return[$nodeKey] = $this->walkFlexFormNode($nodeValue, $valuePointer);
- }
- } else {
- $return[$nodeKey] = $nodeValue;
- }
- }
- return $return;
- }
- return $nodeArray;
- }
-}
// Fluid
'TYPO3\\CMS\\Extbase\\Mvc\\Exception\\InvalidViewHelperException' => \TYPO3\CMS\Extbase\Exception::class,
- 'TYPO3\\CMS\\Extbase\\Mvc\\Exception\\InvalidTemplateResourceException' => \TYPO3Fluid\Fluid\View\Exception\InvalidTemplateResourceException::class
+ 'TYPO3\\CMS\\Extbase\\Mvc\\Exception\\InvalidTemplateResourceException' => \TYPO3Fluid\Fluid\View\Exception\InvalidTemplateResourceException::class,
+
+ // Service
+ 'TYPO3\\CMS\\Extbase\\Service\\FlexFormService' => \TYPO3\CMS\Core\Service\FlexFormService::class,
];
*
* The TYPO3 project - inspiring people to share!
*/
+
+use TYPO3\CMS\Core\Service\FlexFormService;
use TYPO3\CMS\Core\TypoScript\TypoScriptService;
use TYPO3\CMS\Extbase\Configuration\Exception\ParseErrorException;
use TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager;
-use TYPO3\CMS\Extbase\Service\FlexFormService;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\TestingFramework\Core\AccessibleObjectInterface;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
+++ /dev/null
-<?php
-namespace TYPO3\CMS\Extbase\Tests\Unit\Service;
-
-/*
- * This file is part of the TYPO3 CMS project.
- *
- * It is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License, either version 2
- * of the License, or any later version.
- *
- * For the full copyright and license information, please read the
- * LICENSE.txt file that was distributed with this source code.
- *
- * The TYPO3 project - inspiring people to share!
- */
-
-use TYPO3\CMS\Core\Utility\GeneralUtility;
-use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
-
-/**
- * Test case
- */
-class FlexFormServiceTest extends UnitTestCase
-{
- /**
- * @var bool Reset singletons created by subject
- */
- protected $resetSingletonInstances = true;
-
- /**
- * @test
- */
- public function convertFlexFormContentToArrayResolvesComplexArrayStructure()
- {
- $input = '<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
-<T3FlexForms>
- <data>
- <sheet index="sDEF">
- <language index="lDEF">
- <field index="settings.foo">
- <value index="vDEF">Foo-Value</value>
- </field>
- <field index="settings.bar">
- <el index="el">
- <section index="1">
- <itemType index="_arrayContainer">
- <el>
- <field index="baz">
- <value index="vDEF">Baz1-Value</value>
- </field>
- <field index="bum">
- <value index="vDEF">Bum1-Value</value>
- </field>
- <field index="dot.one">
- <value index="vDEF">dot.one-Value</value>
- </field>
- <field index="dot.two">
- <value index="vDEF">dot.two-Value</value>
- </field>
- </el>
- </itemType>
- <itemType index="_TOGGLE">0</itemType>
- </section>
- <section index="2">
- <itemType index="_arrayContainer">
- <el>
- <field index="baz">
- <value index="vDEF">Baz2-Value</value>
- </field>
- <field index="bum">
- <value index="vDEF">Bum2-Value</value>
- </field>
- </el>
- </itemType>
- <itemType index="_TOGGLE">0</itemType>
- </section>
- </el>
- </field>
- </language>
- </sheet>
- </data>
-</T3FlexForms>';
-
- $expected = [
- 'settings' => [
- 'foo' => 'Foo-Value',
- 'bar' => [
- 1 => [
- 'baz' => 'Baz1-Value',
- 'bum' => 'Bum1-Value',
- 'dot' => [
- 'one' => 'dot.one-Value',
- 'two' => 'dot.two-Value',
- ],
- ],
- 2 => [
- 'baz' => 'Baz2-Value',
- 'bum' => 'Bum2-Value'
- ]
- ]
- ]
- ];
-
- // The subject calls xml2array statically, which calls getHash and setHash statically, which uses
- // caches, those need to be mocked.
- $cacheManagerMock = $this->createMock(\TYPO3\CMS\Core\Cache\CacheManager::class);
- $cacheMock = $this->createMock(\TYPO3\CMS\Core\Cache\Frontend\FrontendInterface::class);
- $cacheManagerMock->expects($this->any())->method('getCache')->will($this->returnValue($cacheMock));
- GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Cache\CacheManager::class, $cacheManagerMock);
-
- $flexFormService = $this->getMockBuilder(\TYPO3\CMS\Extbase\Service\FlexFormService::class)
- ->setMethods(['dummy'])
- ->disableOriginalConstructor()
- ->getMock();
- $convertedFlexFormArray = $flexFormService->convertFlexFormContentToArray($input);
- $this->assertSame($expected, $convertedFlexFormArray);
- }
-}
use TYPO3\CMS\Core\Messaging\AbstractMessage;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Messaging\FlashMessageService;
+use TYPO3\CMS\Core\Service\FlexFormService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\StringUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
-use TYPO3\CMS\Extbase\Service\FlexFormService;
use TYPO3\CMS\Form\Mvc\Configuration\Exception\NoSuchFileException;
use TYPO3\CMS\Form\Mvc\Configuration\Exception\ParseErrorException;
use TYPO3\CMS\Form\Mvc\Persistence\Exception\PersistenceManagerException;
use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Core\Resource\StorageRepository;
use TYPO3\CMS\Core\Service\DependencyOrderingService;
+use TYPO3\CMS\Core\Service\FlexFormService;
use TYPO3\CMS\Core\Service\MarkerBasedTemplateService;
use TYPO3\CMS\Core\TimeTracker\TimeTracker;
use TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser;
use TYPO3\CMS\Core\Utility\PathUtility;
use TYPO3\CMS\Core\Utility\StringUtility;
use TYPO3\CMS\Core\Versioning\VersionState;
-use TYPO3\CMS\Extbase\Service\FlexFormService;
use TYPO3\CMS\Frontend\ContentObject\Exception\ContentRenderingException;
use TYPO3\CMS\Frontend\ContentObject\Exception\ExceptionHandlerInterface;
use TYPO3\CMS\Frontend\ContentObject\Exception\ProductionExceptionHandler;
'Deprecation-85761-DeprecatedSaltedPasswordService.rst',
],
],
+ 'TYPO3\CMS\Extbase\Service\FlexFormService' => [
+ 'restFiles' => [
+ 'Deprecation-85802-MoveFlexFormServiceFromEXTextbaseToEXTcore.rst',
+ ],
+ ],
];