/**
  * Preprocesses the preview rendering of a content element of type "table"
  *
  * @param \TYPO3\CMS\Backend\View\PageLayoutView $parentObject Calling parent object
  * @param bool $drawItem Whether to draw the item using the default functionality
  * @param string $headerContent Header content
  * @param string $itemContent Item content
  * @param array $row Record row of tt_content
  *
  * @return void
  */
 public function preProcess(PageLayoutView &$parentObject, &$drawItem, &$headerContent, &$itemContent, array &$row)
 {
     if ($row['CType'] === 'table') {
         if ($row['table_content']) {
             $fieldDelimiter = $row['table_delimiter'] ? chr($row['table_delimiter']) : ',';
             $fieldEnclosure = $row['table_enclosure'] ? chr($row['table_enclosure']) : '"';
             $maximumColumns = $row['cols'] ? $row['cols'] : 0;
             $tableData = CsvUtility::csvToArray($row['table_content'], $fieldDelimiter, $fieldEnclosure, (int) $maximumColumns);
             $linkedContent = '';
             if ($tableData > 0) {
                 $tableRows = '';
                 foreach ($tableData as $tableRow) {
                     if ($tableRow > 0) {
                         $tableColumns = '';
                         foreach ($tableRow as $tableColumn) {
                             $tableColumns .= '<td>' . $tableColumn . '</td>';
                         }
                         $tableRows .= '<tr>' . $tableColumns . '</tr>';
                     }
                 }
                 $linkedContent = '<table class="table table-striped table-bordered">' . $tableRows . '</table>';
             }
             $itemContent .= $parentObject->linkEditContent($linkedContent, $row);
         }
     }
 }
 /**
  * Process CSV field data to split into a multi dimensional array
  *
  * @param ContentObjectRenderer $cObj The data of the content element or page
  * @param array $contentObjectConfiguration The configuration of Content Object
  * @param array $processorConfiguration The configuration of this processor
  * @param array $processedData Key/value store of processed data (e.g. to be passed to a Fluid View)
  * @return array the processed data as key/value store
  */
 public function process(ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData)
 {
     if (isset($processorConfiguration['if.']) && !$cObj->checkIf($processorConfiguration['if.'])) {
         return $processedData;
     }
     // The field name to process
     $fieldName = $cObj->stdWrapValue('fieldName', $processorConfiguration);
     if (empty($fieldName)) {
         return $processedData;
     }
     $originalValue = $cObj->data[$fieldName];
     // Set the target variable
     $targetVariableName = $cObj->stdWrapValue('as', $processorConfiguration, $fieldName);
     // Set the maximum amount of columns
     $maximumColumns = $cObj->stdWrapValue('maximumColumns', $processorConfiguration, 0);
     // Set the field delimiter which is "," by default
     $fieldDelimiter = $cObj->stdWrapValue('fieldDelimiter', $processorConfiguration, ',');
     // Set the field enclosure which is " by default
     $fieldEnclosure = $cObj->stdWrapValue('fieldEnclosure', $processorConfiguration, '"');
     $processedData[$targetVariableName] = CsvUtility::csvToArray($originalValue, $fieldDelimiter, $fieldEnclosure, (int) $maximumColumns);
     return $processedData;
 }
Exemplo n.º 3
0
 /**
  * @dataProvider csvToArrayDataProvider
  * @test
  */
 public function csvToArraySplitsAsExpected($input, $fieldDelimiter, $fieldEnclosure, $rowDelimiter, $maximumColumns, $expectedResult)
 {
     $this->assertEquals($expectedResult, CsvUtility::csvToArray($input, $fieldDelimiter, $fieldEnclosure, $rowDelimiter, $maximumColumns));
 }