‪TYPO3CMS  10.4
FlexFormService.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
20 
25 {
38  public function ‪convertFlexFormContentToArray($flexFormContent, $languagePointer = 'lDEF', $valuePointer = 'vDEF')
39  {
40  $settings = [];
41  $flexFormArray = ‪GeneralUtility::xml2array($flexFormContent);
42  $flexFormArray = $flexFormArray['data'] ?? [];
43  foreach (array_values($flexFormArray) as $languages) {
44  if (!is_array($languages[$languagePointer])) {
45  continue;
46  }
47  foreach ($languages[$languagePointer] as $valueKey => $valueDefinition) {
48  if (strpos($valueKey, '.') === false) {
49  $settings[$valueKey] = $this->‪walkFlexFormNode($valueDefinition, $valuePointer);
50  } else {
51  $valueKeyParts = explode('.', $valueKey);
52  $currentNode = &$settings;
53  foreach ($valueKeyParts as $valueKeyPart) {
54  $currentNode = &$currentNode[$valueKeyPart];
55  }
56  if (is_array($valueDefinition)) {
57  if (array_key_exists($valuePointer, $valueDefinition)) {
58  $currentNode = $valueDefinition[$valuePointer];
59  } else {
60  $currentNode = $this->‪walkFlexFormNode($valueDefinition, $valuePointer);
61  }
62  } else {
63  $currentNode = $valueDefinition;
64  }
65  }
66  }
67  }
68  return $settings;
69  }
70 
78  public function ‪walkFlexFormNode($nodeArray, $valuePointer = 'vDEF')
79  {
80  if (is_array($nodeArray)) {
81  $return = [];
82  foreach ($nodeArray as $nodeKey => $nodeValue) {
83  if ($nodeKey === $valuePointer) {
84  return $nodeValue;
85  }
86  if (in_array($nodeKey, ['el', '_arrayContainer'])) {
87  return $this->‪walkFlexFormNode($nodeValue, $valuePointer);
88  }
89  if (($nodeKey[0] ?? '') === '_') {
90  continue;
91  }
92  if (strpos($nodeKey, '.')) {
93  $nodeKeyParts = explode('.', $nodeKey);
94  $currentNode = &$return;
95  $nodeKeyPartsCount = count($nodeKeyParts);
96  for ($i = 0; $i < $nodeKeyPartsCount - 1; $i++) {
97  $currentNode = &$currentNode[$nodeKeyParts[$i]];
98  }
99  $newNode = [next($nodeKeyParts) => $nodeValue];
100  $subVal = $this->‪walkFlexFormNode($newNode, $valuePointer);
101  $currentNode[key($subVal)] = current($subVal);
102  } elseif (is_array($nodeValue)) {
103  if (array_key_exists($valuePointer, $nodeValue)) {
104  $return[$nodeKey] = $nodeValue[$valuePointer];
105  } else {
106  $return[$nodeKey] = $this->‪walkFlexFormNode($nodeValue, $valuePointer);
107  }
108  } else {
109  $return[$nodeKey] = $nodeValue;
110  }
111  }
112  return $return;
113  }
114  return $nodeArray;
115  }
116 }
‪TYPO3\CMS\Core\Utility\GeneralUtility\xml2array
‪static mixed xml2array($string, $NSprefix='', $reportDocTag=false)
Definition: GeneralUtility.php:1531
‪TYPO3\CMS\Core\Service\FlexFormService
Definition: FlexFormService.php:25
‪TYPO3\CMS\Core\Service\FlexFormService\convertFlexFormContentToArray
‪array convertFlexFormContentToArray($flexFormContent, $languagePointer='lDEF', $valuePointer='vDEF')
Definition: FlexFormService.php:38
‪TYPO3\CMS\Core\Service\FlexFormService\walkFlexFormNode
‪mixed walkFlexFormNode($nodeArray, $valuePointer='vDEF')
Definition: FlexFormService.php:78
‪TYPO3\CMS\Core\Service
Definition: AbstractService.php:16
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:23
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46