1<?php 2 3/* 4 * This file is part of the TYPO3 CMS project. 5 * 6 * It is free software; you can redistribute it and/or modify it under 7 * the terms of the GNU General Public License, either version 2 8 * of the License, or any later version. 9 * 10 * For the full copyright and license information, please read the 11 * LICENSE.txt file that was distributed with this source code. 12 * 13 * The TYPO3 project - inspiring people to share! 14 */ 15 16namespace TYPO3\CMS\Backend\Form\Container; 17 18use TYPO3\CMS\Core\Localization\LanguageService; 19use TYPO3\CMS\Core\Utility\GeneralUtility; 20 21/** 22 * Render all tabs of a record that has tabs. 23 * 24 * This container is called from FullRecordContainer and resolves the --div-- structure, 25 * operates on given fieldArrays and calls a PaletteAndSingleContainer for each single tab. 26 */ 27class TabsContainer extends AbstractContainer 28{ 29 /** 30 * Entry method 31 * 32 * @return array As defined in initializeResultArray() of AbstractNode 33 * @throws \RuntimeException 34 */ 35 public function render() 36 { 37 $languageService = $this->getLanguageService(); 38 39 // All the fields to handle in a flat list 40 $fieldsArray = $this->data['fieldsArray']; 41 42 // Create a nested array from flat fieldArray list 43 $tabsArray = []; 44 // First element will be a --div--, so it is safe to start -1 here to trigger 0 as first array index 45 $currentTabIndex = -1; 46 foreach ($fieldsArray as $fieldString) { 47 $fieldArray = $this->explodeSingleFieldShowItemConfiguration($fieldString); 48 if ($fieldArray['fieldName'] === '--div--') { 49 $currentTabIndex++; 50 if (empty($fieldArray['fieldLabel'])) { 51 throw new \RuntimeException( 52 'A --div-- has no label (--div--;fieldLabel) in showitem of ' . implode(',', $fieldsArray), 53 1426454001 54 ); 55 } 56 $tabsArray[$currentTabIndex] = [ 57 'label' => $languageService->sL($fieldArray['fieldLabel']), 58 'elements' => [], 59 ]; 60 } else { 61 $tabsArray[$currentTabIndex]['elements'][] = $fieldArray; 62 } 63 } 64 65 $resultArray = $this->initializeResultArray(); 66 $resultArray['requireJsModules'][] = 'TYPO3/CMS/Backend/Tabs'; 67 68 $domIdPrefix = 'DTM-' . GeneralUtility::shortMD5($this->data['tableName'] . $this->data['databaseRow']['uid']); 69 $tabCounter = 0; 70 $tabElements = []; 71 foreach ($tabsArray as $tabWithLabelAndElements) { 72 $tabCounter++; 73 $elements = $tabWithLabelAndElements['elements']; 74 75 // Merge elements of this tab into a single list again and hand over to 76 // palette and single field container to render this group 77 $options = $this->data; 78 $options['tabAndInlineStack'][] = [ 79 'tab', 80 $domIdPrefix . '-' . $tabCounter, 81 ]; 82 $options['fieldsArray'] = []; 83 foreach ($elements as $element) { 84 $options['fieldsArray'][] = implode(';', $element); 85 } 86 $options['renderType'] = 'paletteAndSingleContainer'; 87 $childArray = $this->nodeFactory->create($options)->render(); 88 89 if ($childArray['html'] !== '') { 90 $tabElements[] = [ 91 'label' => $tabWithLabelAndElements['label'], 92 'content' => $childArray['html'], 93 ]; 94 } 95 $resultArray = $this->mergeChildReturnIntoExistingResult($resultArray, $childArray, false); 96 } 97 98 $resultArray['html'] = $this->renderTabMenu($tabElements, $domIdPrefix); 99 return $resultArray; 100 } 101 102 /** 103 * @return LanguageService 104 */ 105 protected function getLanguageService() 106 { 107 return $GLOBALS['LANG']; 108 } 109} 110