TYPO3 CMS  TYPO3_6-2
FlexFormService.php
Go to the documentation of this file.
1 <?php
3 
20 
33  public function convertFlexFormContentToArray($flexFormContent, $languagePointer = 'lDEF', $valuePointer = 'vDEF') {
34  $settings = array();
35  $flexFormArray = \TYPO3\CMS\Core\Utility\GeneralUtility::xml2array($flexFormContent);
36  $flexFormArray = isset($flexFormArray['data']) ? $flexFormArray['data'] : array();
37  foreach (array_values($flexFormArray) as $languages) {
38  if (!is_array($languages[$languagePointer])) {
39  continue;
40  }
41  foreach ($languages[$languagePointer] as $valueKey => $valueDefinition) {
42  if (strpos($valueKey, '.') === FALSE) {
43  $settings[$valueKey] = $this->walkFlexFormNode($valueDefinition, $valuePointer);
44  } else {
45  $valueKeyParts = explode('.', $valueKey);
46  $currentNode = &$settings;
47  foreach ($valueKeyParts as $valueKeyPart) {
48  $currentNode = &$currentNode[$valueKeyPart];
49  }
50  if (is_array($valueDefinition)) {
51  if (array_key_exists($valuePointer, $valueDefinition)) {
52  $currentNode = $valueDefinition[$valuePointer];
53  } else {
54  $currentNode = $this->walkFlexFormNode($valueDefinition, $valuePointer);
55  }
56  } else {
57  $currentNode = $valueDefinition;
58  }
59  }
60  }
61  }
62  return $settings;
63  }
64 
72  public function walkFlexFormNode($nodeArray, $valuePointer = 'vDEF') {
73  if (is_array($nodeArray)) {
74  $return = array();
75  foreach ($nodeArray as $nodeKey => $nodeValue) {
76  if ($nodeKey === $valuePointer) {
77  return $nodeValue;
78  }
79  if (in_array($nodeKey, array('el', '_arrayContainer'))) {
80  return $this->walkFlexFormNode($nodeValue, $valuePointer);
81  }
82  if ($nodeKey[0] === '_') {
83  continue;
84  }
85  if (strpos($nodeKey, '.')) {
86  $nodeKeyParts = explode('.', $nodeKey);
87  $currentNode = &$return;
88  for ($i = 0; $i < count($nodeKeyParts) - 1; $i++) {
89  $currentNode = &$currentNode[$nodeKeyParts[$i]];
90  }
91  $newNode = array(next($nodeKeyParts) => $nodeValue);
92  $currentNode = $this->walkFlexFormNode($newNode, $valuePointer);
93  } elseif (is_array($nodeValue)) {
94  if (array_key_exists($valuePointer, $nodeValue)) {
95  $return[$nodeKey] = $nodeValue[$valuePointer];
96  } else {
97  $return[$nodeKey] = $this->walkFlexFormNode($nodeValue, $valuePointer);
98  }
99  } else {
100  $return[$nodeKey] = $nodeValue;
101  }
102  }
103  return $return;
104  }
105  return $nodeArray;
106  }
107 }
walkFlexFormNode($nodeArray, $valuePointer='vDEF')
convertFlexFormContentToArray($flexFormContent, $languagePointer='lDEF', $valuePointer='vDEF')
static xml2array($string, $NSprefix='', $reportDocTag=FALSE)