TYPO3 CMS  TYPO3_8-7
CommaSeparatedValueProcessor.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
20 
57 {
67  public function process(ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData)
68  {
69  if (isset($processorConfiguration['if.']) && !$cObj->checkIf($processorConfiguration['if.'])) {
70  return $processedData;
71  }
72 
73  // The field name to process
74  $fieldName = $cObj->stdWrapValue('fieldName', $processorConfiguration);
75  if (empty($fieldName)) {
76  return $processedData;
77  }
78 
79  $originalValue = $cObj->data[$fieldName];
80 
81  // Set the target variable
82  $targetVariableName = $cObj->stdWrapValue('as', $processorConfiguration, $fieldName);
83 
84  // Set the maximum amount of columns
85  $maximumColumns = $cObj->stdWrapValue('maximumColumns', $processorConfiguration, 0);
86 
87  // Set the field delimiter which is "," by default
88  $fieldDelimiter = $cObj->stdWrapValue('fieldDelimiter', $processorConfiguration, ',');
89 
90  // Set the field enclosure which is " by default
91  $fieldEnclosure = $cObj->stdWrapValue('fieldEnclosure', $processorConfiguration, '"');
92 
93  $processedData[$targetVariableName] = CsvUtility::csvToArray(
94  $originalValue,
95  $fieldDelimiter,
96  $fieldEnclosure,
97  (int)$maximumColumns
98  );
99 
100  return $processedData;
101  }
102 }
static csvToArray($input, $fieldDelimiter=',', $fieldEnclosure='"', $maximumColumns = 0)
Definition: CsvUtility.php:33
process(ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData)