TYPO3  7.6
ContentRepository.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Form\Domain\Repository;
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 
19 
24 {
32  public function getRecord()
33  {
34  $record = false;
35  $getPostVariables = GeneralUtility::_GP('P');
36  $table = (string)$getPostVariables['table'];
37  $recordId = (int)$getPostVariables['uid'];
38  $row = BackendUtility::getRecord($table, $recordId);
39  if (is_array($row)) {
40  // strip off the leading "[Translate to XY]" text after localizing the original record
41  $languageField = $GLOBALS['TCA']['tt_content']['ctrl']['languageField'];
42  $transOrigPointerField = $GLOBALS['TCA']['tt_content']['ctrl']['transOrigPointerField'];
43  if ($row[$languageField] > 0 && $row[$transOrigPointerField] > 0) {
44  $bodytext = preg_replace('/^\[.*?\] /', '', $row['bodytext'], 1);
45  } else {
46  $bodytext = $row['bodytext'];
47  }
48 
50  $typoScriptParser = GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::class);
51  $typoScriptParser->parse($bodytext);
53  $record = GeneralUtility::makeInstance(\TYPO3\CMS\Form\Domain\Model\Content::class);
54  $record->setUid($row['uid']);
55  $record->setPageId($row['pid']);
56  $record->setTyposcript($typoScriptParser->setup);
57  }
58  return $record;
59  }
60 
66  public function hasRecord()
67  {
68  return $this->getRecord() !== false;
69  }
70 
76  public function save()
77  {
78  $json = GeneralUtility::_GP('configuration');
79  $parameters = GeneralUtility::_GP('P');
80  $success = false;
82  $converter = GeneralUtility::makeInstance(\TYPO3\CMS\Form\Domain\Factory\JsonToTypoScript::class);
83  $typoscript = $converter->convert($json);
84  if ($typoscript) {
85  // Make TCEmain object:
87  $tce = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
88  $tce->stripslashes_values = 0;
89  // Put content into the data array:
90  $data = array();
91  $data[$parameters['table']][$parameters['uid']][$parameters['field']] = $typoscript;
92  // Perform the update:
93  $tce->start($data, array());
94  $tce->process_datamap();
95  $success = true;
96  }
97  return $success;
98  }
99 
105  public function getRecordAsJson()
106  {
107  $json = false;
108  $record = $this->getRecord();
109  if ($record) {
110  $typoscript = $record->getTyposcript();
112  $converter = GeneralUtility::makeInstance(\TYPO3\CMS\Form\Utility\TypoScriptToJsonConverter::class);
113  $json = $converter->convert($typoscript);
114  }
115  return $json;
116  }
117 }