1<?php 2 3declare(strict_types=1); 4 5/* 6 * This file is part of the TYPO3 CMS project. 7 * 8 * It is free software; you can redistribute it and/or modify it under 9 * the terms of the GNU General Public License, either version 2 10 * of the License, or any later version. 11 * 12 * For the full copyright and license information, please read the 13 * LICENSE.txt file that was distributed with this source code. 14 * 15 * The TYPO3 project - inspiring people to share! 16 */ 17 18namespace TYPO3\CMS\Backend\Form\FieldWizard; 19 20use TYPO3\CMS\Backend\Form\AbstractNode; 21use TYPO3\CMS\Backend\Utility\BackendUtility; 22use TYPO3\CMS\Core\Imaging\Icon; 23use TYPO3\CMS\Core\Imaging\IconFactory; 24use TYPO3\CMS\Core\Utility\GeneralUtility; 25 26/** 27 * Render values of "other" languages. If editing a localized row, this is typically 28 * the content value of the according default record, but it may render field values 29 * of other languages too, depending on configuration. 30 */ 31class OtherLanguageContent extends AbstractNode 32{ 33 /** 34 * Render other language content if enabled. 35 * 36 * @return array 37 */ 38 public function render(): array 39 { 40 $result = $this->initializeResultArray(); 41 42 $fieldName = $this->data['fieldName']; 43 $fieldConfig = $this->data['processedTca']['columns'][$fieldName]; 44 $fieldType = $fieldConfig['config']['type']; 45 $l10nDisplay = $this->data['parameterArray']['fieldConf']['l10n_display'] ?? ''; 46 $defaultLanguageRow = $this->data['defaultLanguageRow'] ?? null; 47 if (!is_array($defaultLanguageRow) 48 || GeneralUtility::inList($l10nDisplay, 'hideDiff') 49 || GeneralUtility::inList($l10nDisplay, 'defaultAsReadonly') 50 || $fieldType === 'inline' 51 || $fieldType === 'flex' 52 || (in_array($fieldType, ['select', 'category', 'group'], true) && isset($fieldConfig['config']['MM'])) 53 ) { 54 // Early return if there is no default language row or the display is disabled 55 return $result; 56 } 57 58 $iconFactory = GeneralUtility::makeInstance(IconFactory::class); 59 $table = $this->data['tableName']; 60 $html = []; 61 $defaultLanguageValue = BackendUtility::getProcessedValue( 62 $table, 63 $fieldName, 64 $defaultLanguageRow[$fieldName], 65 0, 66 true, 67 false, 68 $defaultLanguageRow['uid'], 69 true, 70 $defaultLanguageRow['pid'] 71 ) ?? ''; 72 if ($defaultLanguageValue !== '') { 73 $iconIdentifier = ($this->data['systemLanguageRows'][0]['flagIconIdentifier'] ?? false) ?: 'flags-multiple'; 74 $html[] = '<div class="t3-form-original-language">'; 75 $html[] = $iconFactory->getIcon($iconIdentifier, Icon::SIZE_SMALL)->render(); 76 $html[] = $this->previewFieldValue($defaultLanguageValue); 77 $html[] = '</div>'; 78 } 79 $additionalPreviewLanguages = $this->data['additionalLanguageRows']; 80 foreach ($additionalPreviewLanguages as $previewLanguage) { 81 $defaultLanguageValue = BackendUtility::getProcessedValue( 82 $table, 83 $fieldName, 84 $previewLanguage[$fieldName], 85 0, 86 true 87 ) ?? ''; 88 if ($defaultLanguageValue !== '') { 89 $html[] = '<div class="t3-form-original-language">'; 90 $html[] = $iconFactory->getIcon($this->data['systemLanguageRows'][$previewLanguage['sys_language_uid']]['flagIconIdentifier'], Icon::SIZE_SMALL)->render(); 91 $html[] = $this->previewFieldValue($defaultLanguageValue); 92 $html[] = '</div>'; 93 } 94 } 95 $result['html'] = implode(LF, $html); 96 return $result; 97 } 98 99 /** 100 * Rendering preview output of a field value which is not shown as a form field but just outputted. 101 * 102 * @param string $value The value to output 103 * @return string HTML formatted output 104 */ 105 protected function previewFieldValue($value) 106 { 107 return nl2br(htmlspecialchars((string)$value)); 108 } 109} 110