‪TYPO3CMS  ‪main
OtherLanguageContent.php
Go to the documentation of this file.
1 <?php
2 
3 declare(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 
19 
21 use TYPO3\CMS\Backend\Utility\BackendUtility;
23 use TYPO3\CMS\Core\Imaging\IconSize;
25 
32 {
33  public function ‪__construct(
34  private readonly ‪IconFactory $iconFactory,
35  ) {}
36 
40  public function ‪render(): array
41  {
42  $result = $this->‪initializeResultArray();
43 
44  $fieldName = $this->data['fieldName'];
45  $fieldConfig = $this->data['processedTca']['columns'][$fieldName];
46  $fieldType = $fieldConfig['config']['type'];
47  $l10nDisplay = $this->data['parameterArray']['fieldConf']['l10n_display'] ?? '';
48  $defaultLanguageRow = $this->data['defaultLanguageRow'] ?? null;
49  if (!is_array($defaultLanguageRow)
50  || ‪GeneralUtility::inList($l10nDisplay, 'hideDiff')
51  || ‪GeneralUtility::inList($l10nDisplay, 'defaultAsReadonly')
52  || $fieldType === 'inline'
53  || $fieldType === 'file'
54  || $fieldType === 'flex'
55  || (in_array($fieldType, ['select', 'category', 'group'], true) && isset($fieldConfig['config']['MM']))
56  ) {
57  // Early return if there is no default language row or the display is disabled
58  return $result;
59  }
60 
61  $table = $this->data['tableName'];
62  $html = [];
63  $defaultLanguageValue = BackendUtility::getProcessedValue(
64  $table,
65  $fieldName,
66  $defaultLanguageRow[$fieldName],
67  0,
68  true,
69  false,
70  $defaultLanguageRow['uid'],
71  true,
72  $defaultLanguageRow['pid']
73  ) ?? '';
74  if ($defaultLanguageValue !== '') {
75  $iconIdentifier = ($this->data['systemLanguageRows'][0]['flagIconIdentifier'] ?? false) ?: 'flags-multiple';
76  $html[] = '<div class="t3-form-original-language">';
77  $html[] = $this->iconFactory->getIcon($iconIdentifier, IconSize::SMALL)->render();
78  $html[] = $this->‪previewFieldValue($defaultLanguageValue);
79  $html[] = '</div>';
80  }
81  $additionalPreviewLanguages = $this->data['additionalLanguageRows'];
82  foreach ($additionalPreviewLanguages as $previewLanguage) {
83  $defaultLanguageValue = BackendUtility::getProcessedValue(
84  $table,
85  $fieldName,
86  $previewLanguage[$fieldName],
87  0,
88  true
89  ) ?? '';
90  if ($defaultLanguageValue !== '') {
91  $html[] = '<div class="t3-form-original-language">';
92  $html[] = $this->iconFactory->getIcon($this->data['systemLanguageRows'][$previewLanguage['sys_language_uid']]['flagIconIdentifier'], IconSize::SMALL)->render();
93  $html[] = $this->‪previewFieldValue($defaultLanguageValue);
94  $html[] = '</div>';
95  }
96  }
97  $result['html'] = implode(LF, $html);
98  return $result;
99  }
100 
107  protected function ‪previewFieldValue($value)
108  {
109  return nl2br(htmlspecialchars((string)$value));
110  }
111 }
‪TYPO3\CMS\Backend\Form\FieldWizard\OtherLanguageContent\render
‪render()
Definition: OtherLanguageContent.php:40
‪TYPO3\CMS\Backend\Form\FieldWizard\OtherLanguageContent
Definition: OtherLanguageContent.php:32
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Backend\Form\FieldWizard\OtherLanguageContent\previewFieldValue
‪string previewFieldValue($value)
Definition: OtherLanguageContent.php:107
‪TYPO3\CMS\Backend\Form\FieldWizard
Definition: DefaultLanguageDifferences.php:18
‪TYPO3\CMS\Core\Utility\GeneralUtility\inList
‪static bool inList($list, $item)
Definition: GeneralUtility.php:422
‪TYPO3\CMS\Backend\Form\AbstractNode
Definition: AbstractNode.php:29
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Backend\Form\FieldWizard\OtherLanguageContent\__construct
‪__construct(private readonly IconFactory $iconFactory,)
Definition: OtherLanguageContent.php:33
‪TYPO3\CMS\Backend\Form\AbstractNode\initializeResultArray
‪initializeResultArray()
Definition: AbstractNode.php:77