c6682c089c5c6803991943131a80f7259896e8f9
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Form / Container / SoloFieldContainer.php
1 <?php
2 namespace TYPO3\CMS\Backend\Form\Container;
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
17 use TYPO3\CMS\Core\Utility\GeneralUtility;
18 use TYPO3\CMS\Lang\LanguageService;
19
20 /**
21 * An entry container to render just a single field.
22 *
23 * The container operates on $this->globalOptions['singleFieldToRender'] to render
24 * this field. It initializes language stuff and prepares data in globalOptions for
25 * processing of the single field in SingleFieldContainer.
26 *
27 * @todo: It should be possible to merge this container to ListOfFieldsContainer
28 */
29 class SoloFieldContainer extends AbstractContainer
30 {
31 /**
32 * Entry method
33 *
34 * @return array As defined in initializeResultArray() of AbstractNode
35 */
36 public function render()
37 {
38 $table = $this->data['tableName'];
39 $fieldToRender = $this->data['singleFieldToRender'];
40 $recordTypeValue = $this->data['recordTypeValue'];
41 $resultArray = $this->initializeResultArray();
42
43 // Load the description content for the table if requested
44 if ($GLOBALS['TCA'][$table]['interface']['always_description']) {
45 $languageService = $this->getLanguageService();
46 $languageService->loadSingleTableDescription($table);
47 }
48
49 $itemList = $this->data['processedTca']['types'][$recordTypeValue]['showitem'];
50 $fields = GeneralUtility::trimExplode(',', $itemList, true);
51 foreach ($fields as $fieldString) {
52 $fieldConfiguration = $this->explodeSingleFieldShowItemConfiguration($fieldString);
53 $fieldName = $fieldConfiguration['fieldName'];
54 if ((string)$fieldName === (string)$fieldToRender) {
55 // Field is in showitem configuration
56 // @todo: This field is not rendered if it is "hidden" in a palette!
57 if ($GLOBALS['TCA'][$table]['columns'][$fieldName]) {
58 $options = $this->data;
59 $options['fieldName'] = $fieldName;
60 $options['renderType'] = 'singleFieldContainer';
61 $resultArray = $this->nodeFactory->create($options)->render();
62 }
63 }
64 }
65
66 return $resultArray;
67 }
68
69 /**
70 * @return LanguageService
71 */
72 protected function getLanguageService()
73 {
74 return $GLOBALS['LANG'];
75 }
76 }