TYPO3 CMS  TYPO3_8-7
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  $html[] = '<div class="t3-form-original-language">';
72  $html[] = $iconFactory->getIcon($this->data['systemLanguageRows'][0]['flagIconIdentifier'], Icon::SIZE_SMALL)->render();
73  $html[] = $this->previewFieldValue($defaultLanguageValue, $fieldConfig, $fieldName);
74  $html[] = '</div>';
75  }
76  $additionalPreviewLanguages = $this->data['additionalLanguageRows'];
77  foreach ($additionalPreviewLanguages as $previewLanguage) {
78  $defaultLanguageValue = BackendUtility::getProcessedValue(
79  $table,
80  $fieldName,
81  $previewLanguage[$fieldName],
82  0,
83  true
84  );
85  if ($defaultLanguageValue !== '') {
86  $html[] = '<div class="t3-form-original-language">';
87  $html[] = $iconFactory->getIcon($this->data['systemLanguageRows'][$previewLanguage['sys_language_uid']]['flagIconIdentifier'], Icon::SIZE_SMALL)->render();
88  $html[] = $this->previewFieldValue($defaultLanguageValue, $fieldConfig, $fieldName);
89  $html[] = '</div>';
90  }
91  }
92  $result['html'] = implode(LF, $html);
93  return $result;
94  }
95 
104  protected function previewFieldValue($value, $config, $field = '')
105  {
106  $value = (string)$value;
107  if ($config['config']['type'] === 'group'
108  && ($config['config']['internal_type'] === 'file' || $config['config']['internal_type'] === 'file_reference')
109  ) {
110  // Ignore upload folder if internal_type is file_reference
111  if ($config['config']['internal_type'] === 'file_reference') {
112  $config['config']['uploadfolder'] = '';
113  }
114  $table = 'tt_content';
115  // Making the array of file items:
116  $itemArray = GeneralUtility::trimExplode(',', $value, true);
117  // Showing thumbnails:
118  $imgs = [];
119  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
120  foreach ($itemArray as $imgRead) {
121  $imgParts = explode('|', $imgRead);
122  $imgPath = rawurldecode($imgParts[0]);
123  $rowCopy = [];
124  $rowCopy[$field] = $imgPath;
125  // Icon + click menu:
126  $absFilePath = GeneralUtility::getFileAbsFileName($config['config']['uploadfolder'] ? $config['config']['uploadfolder'] . '/' . $imgPath : $imgPath);
127  $fileInformation = pathinfo($imgPath);
128  $title = $fileInformation['basename'] . ($absFilePath && @is_file($absFilePath))
129  ? ' (' . GeneralUtility::formatSize(filesize($absFilePath)) . ')'
130  : ' - FILE NOT FOUND!';
131  $fileIcon = '<span title="' . htmlspecialchars($title) . '">' . $iconFactory->getIconForFileExtension($fileInformation['extension'], Icon::SIZE_SMALL)->render() . '</span>';
132  $imgs[] =
133  '<span class="text-nowrap">' .
134  BackendUtility::thumbCode(
135  $rowCopy,
136  $table,
137  $field,
138  '',
139  '',
140  $config['config']['uploadfolder'],
141  0,
142  ' align="middle"'
143  ) .
144  ($absFilePath ? BackendUtility::wrapClickMenuOnIcon($fileIcon, $absFilePath, 0) : $fileIcon) .
145  $imgPath .
146  '</span>';
147  }
148  return implode('<br />', $imgs);
149  }
150  return nl2br(htmlspecialchars($value));
151  }
152 }
static wrapClickMenuOnIcon( $content, $table, $uid=0, $context='', $_addParams='', $_enDisItems='', $returnTagParameters=false)
static getFileAbsFileName($filename, $_=null, $_2=null)
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
static makeInstance($className,... $constructorArguments)
static formatSize($sizeInBytes, $labels='', $base=0)