‪TYPO3CMS  9.5
OtherLanguageContent.php
Go to the documentation of this file.
1 <?php
2 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 
23 
30 {
36  public function ‪render(): array
37  {
38  $result = $this->‪initializeResultArray();
39 
40  $fieldName = $this->data['fieldName'];
41  $fieldConfig = $this->data['processedTca']['columns'][$fieldName];
42  $l10nDisplay = $this->data['parameterArray']['fieldConf']['l10n_display'] ?? '';
43  $defaultLanguageRow = $this->data['defaultLanguageRow'] ?? null;
44  if (!is_array($defaultLanguageRow)
45  || GeneralUtility::inList($l10nDisplay, 'hideDiff')
46  || GeneralUtility::inList($l10nDisplay, 'defaultAsReadonly')
47  || $fieldConfig['config']['type'] === 'inline'
48  || $fieldConfig['config']['type'] === 'flex'
49  || ($fieldConfig['config']['type'] === 'group' && isset($fieldConfig['config']['MM']))
50  || ($fieldConfig['config']['type'] === 'select' && isset($fieldConfig['config']['MM']))
51  ) {
52  // Early return if there is no default language row or the display is disabled
53  return $result;
54  }
55 
56  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
57  $table = $this->data['tableName'];
58  $html = [];
59  $defaultLanguageValue = ‪BackendUtility::getProcessedValue(
60  $table,
61  $fieldName,
62  $defaultLanguageRow[$fieldName],
63  0,
64  true,
65  false,
66  $defaultLanguageRow['uid'],
67  true,
68  $defaultLanguageRow['pid']
69  );
70  if ($defaultLanguageValue !== '') {
71  $iconIdentifier = $this->data['systemLanguageRows'][0]['flagIconIdentifier'] ?: 'flags-multiple';
72  $html[] = '<div class="t3-form-original-language">';
73  $html[] = $iconFactory->getIcon($iconIdentifier, ‪Icon::SIZE_SMALL)->render();
74  $html[] = $this->‪previewFieldValue($defaultLanguageValue, $fieldConfig, $fieldName);
75  $html[] = '</div>';
76  }
77  $additionalPreviewLanguages = $this->data['additionalLanguageRows'];
78  foreach ($additionalPreviewLanguages as $previewLanguage) {
79  $defaultLanguageValue = ‪BackendUtility::getProcessedValue(
80  $table,
81  $fieldName,
82  $previewLanguage[$fieldName],
83  0,
84  true
85  );
86  if ($defaultLanguageValue !== '') {
87  $html[] = '<div class="t3-form-original-language">';
88  $html[] = $iconFactory->getIcon($this->data['systemLanguageRows'][$previewLanguage['sys_language_uid']]['flagIconIdentifier'], ‪Icon::SIZE_SMALL)->render();
89  $html[] = $this->‪previewFieldValue($defaultLanguageValue, $fieldConfig, $fieldName);
90  $html[] = '</div>';
91  }
92  }
93  $result['html'] = implode(LF, $html);
94  return $result;
95  }
96 
105  protected function ‪previewFieldValue($value, $config, $field = '')
106  {
107  // @deprecated since TYPO3 v9, will be removed in TYPO3 v10.0. Deprecation logged by TcaMigration class.
108  $value = (string)$value;
109  if ($config['config']['type'] === 'group'
110  && ($config['config']['internal_type'] === 'file' || $config['config']['internal_type'] === 'file_reference')
111  ) {
112  // Ignore upload folder if internal_type is file_reference
113  if ($config['config']['internal_type'] === 'file_reference') {
114  $config['config']['uploadfolder'] = '';
115  }
116  $table = 'tt_content';
117  // Making the array of file items:
118  $itemArray = GeneralUtility::trimExplode(',', $value, true);
119  // Showing thumbnails:
120  $imgs = [];
121  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
122  foreach ($itemArray as $imgRead) {
123  $imgParts = explode('|', $imgRead);
124  $imgPath = rawurldecode($imgParts[0]);
125  $rowCopy = [];
126  $rowCopy[$field] = $imgPath;
127  // Icon + click menu:
128  $absFilePath = GeneralUtility::getFileAbsFileName($config['config']['uploadfolder'] ? $config['config']['uploadfolder'] . '/' . $imgPath : $imgPath);
129  $fileInformation = pathinfo($imgPath);
130  $title = $fileInformation['basename'] . ($absFilePath && @is_file($absFilePath))
131  ? ' (' . GeneralUtility::formatSize(filesize($absFilePath)) . ')'
132  : ' - FILE NOT FOUND!';
133  $fileIcon = '<span title="' . htmlspecialchars($title) . '">' . $iconFactory->getIconForFileExtension($fileInformation['extension'], ‪Icon::SIZE_SMALL)->render() . '</span>';
134  $imgs[] =
135  '<span class="text-nowrap">' .
137  $rowCopy,
138  $table,
139  $field,
140  '',
141  '',
142  $config['config']['uploadfolder'],
143  0,
144  ' align="middle"'
145  ) .
146  ($absFilePath ? ‪BackendUtility::wrapClickMenuOnIcon($fileIcon, $absFilePath) : $fileIcon) .
147  $imgPath .
148  '</span>';
149  }
150  return implode('<br />', $imgs);
151  }
152  return nl2br(htmlspecialchars($value));
153  }
154 }
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:29
‪TYPO3\CMS\Backend\Form\AbstractNode\initializeResultArray
‪array initializeResultArray()
Definition: AbstractNode.php:88
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:25
‪TYPO3\CMS\Backend\Form\FieldWizard\OtherLanguageContent
Definition: OtherLanguageContent.php:30
‪TYPO3\CMS\Backend\Utility\BackendUtility\thumbCode
‪static string thumbCode( $row, $table, $field, $backPath='', $thumbScript='', $uploaddir=null, $abs=0, $tparams='', $size='', $linkInfoPopup=true)
Definition: BackendUtility.php:1338
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:31
‪TYPO3\CMS\Backend\Form\FieldWizard\OtherLanguageContent\previewFieldValue
‪string previewFieldValue($value, $config, $field='')
Definition: OtherLanguageContent.php:105
‪TYPO3\CMS\Backend\Utility\BackendUtility\wrapClickMenuOnIcon
‪static string wrapClickMenuOnIcon( $content, $table, $uid=0, $context='', $_addParams='', $_enDisItems='', $returnTagParameters=false)
Definition: BackendUtility.php:2759
‪TYPO3\CMS\Backend\Form\FieldWizard
Definition: DefaultLanguageDifferences.php:3
‪TYPO3\CMS\Backend\Form\FieldWizard\OtherLanguageContent\render
‪array render()
Definition: OtherLanguageContent.php:36
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:72
‪TYPO3\CMS\Backend\Utility\BackendUtility\getProcessedValue
‪static string null getProcessedValue( $table, $col, $value, $fixed_lgd_chars=0, $defaultPassthrough=false, $noRecordLookup=false, $uid=0, $forceResult=true, $pid=0)
Definition: BackendUtility.php:1933
‪TYPO3\CMS\Backend\Form\AbstractNode
Definition: AbstractNode.php:27
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45