Skip to content

Commit 063e78c

Browse files
committed
[TASK] Initial
0 parents  commit 063e78c

File tree

9 files changed

+630
-0
lines changed

9 files changed

+630
-0
lines changed

Classes/Configuration.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace StudioMitte\RecordlistThumbnail;
5+
6+
use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationExtensionNotConfiguredException;
7+
use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationPathDoesNotExistException;
8+
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
9+
use TYPO3\CMS\Core\Utility\GeneralUtility;
10+
11+
class Configuration
12+
{
13+
14+
/**
15+
* @return string[]
16+
*/
17+
public function getFields(): array
18+
{
19+
return $this->getSettings();
20+
}
21+
22+
public function getField(string $tableName): string
23+
{
24+
$settings = $this->getSettings();
25+
return $settings[$tableName] ?? '';
26+
}
27+
28+
/**
29+
* @return string[]
30+
*/
31+
protected function getSettings(): array
32+
{
33+
try {
34+
$configuration = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('recordlist_thumbnail', 'list');
35+
$settings = [];
36+
foreach (GeneralUtility::trimExplode(',', $configuration, true) as $item) {
37+
$split = GeneralUtility::trimExplode('=', $item, true);
38+
if (count($split) !== 2) {
39+
continue;
40+
}
41+
$settings[$split[0]] = $split[1];
42+
}
43+
return $settings;
44+
} catch (ExtensionConfigurationExtensionNotConfiguredException $e) {
45+
// do nothing
46+
} catch (ExtensionConfigurationPathDoesNotExistException $e) {
47+
// do nothing
48+
}
49+
50+
return [];
51+
}
52+
}
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace StudioMitte\RecordlistThumbnail\Xclass;
6+
7+
use StudioMitte\RecordlistThumbnail\Configuration;
8+
use TYPO3\CMS\Backend\Utility\BackendUtility;
9+
use TYPO3\CMS\Core\Imaging\Icon;
10+
use TYPO3\CMS\Core\Utility\GeneralUtility;
11+
use TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList;
12+
13+
class XclassedDatabaseRecordList extends DatabaseRecordList {
14+
15+
public function renderListRow($table, array $row, int $indent, array $translations, bool $translationEnabled)
16+
{
17+
// xclass begin
18+
$thumbnailField = $this->getThumbnailField($table);
19+
// xclass end
20+
$titleCol = $GLOBALS['TCA'][$table]['ctrl']['label'] ?? '';
21+
$languageService = $this->getLanguageService();
22+
$rowOutput = '';
23+
$id_orig = $this->id;
24+
// If in search mode, make sure the preview will show the correct page
25+
if ((string)$this->searchString !== '') {
26+
$this->id = $row['pid'];
27+
}
28+
29+
$tagAttributes = [
30+
'class' => [],
31+
'data-table' => $table,
32+
'title' => 'id=' . $row['uid'],
33+
];
34+
35+
// Add active class to record of current link
36+
if (
37+
isset($this->currentLink['tableNames'])
38+
&& (int)$this->currentLink['uid'] === (int)$row['uid']
39+
&& GeneralUtility::inList($this->currentLink['tableNames'], $table)
40+
) {
41+
$tagAttributes['class'][] = 'active';
42+
}
43+
// Overriding with versions background color if any:
44+
if (!empty($row['_CSSCLASS'])) {
45+
$tagAttributes['class'] = [$row['_CSSCLASS']];
46+
}
47+
48+
$tagAttributes['class'][] = 't3js-entity';
49+
50+
// Preparing and getting the data-array
51+
$theData = [];
52+
$deletePlaceholderClass = '';
53+
foreach ($this->fieldArray as $fCol) {
54+
if ($fCol === $titleCol) {
55+
$recTitle = BackendUtility::getRecordTitle($table, $row, false, true);
56+
$warning = '';
57+
// If the record is edit-locked by another user, we will show a little warning sign:
58+
$lockInfo = BackendUtility::isRecordLocked($table, $row['uid']);
59+
if ($lockInfo) {
60+
$warning = '<span tabindex="0" data-bs-toggle="tooltip" data-bs-placement="right"'
61+
. ' title="' . htmlspecialchars($lockInfo['msg']) . '"'
62+
. ' aria-label="' . htmlspecialchars($lockInfo['msg']) . '">'
63+
. $this->iconFactory->getIcon('warning-in-use', Icon::SIZE_SMALL)->render()
64+
. '</span>';
65+
}
66+
if ($this->isRecordDeletePlaceholder($row)) {
67+
// Delete placeholder records do not link to formEngine edit and are rendered strike-through
68+
$deletePlaceholderClass = ' deletePlaceholder';
69+
$theData[$fCol] = $theData['__label'] =
70+
$warning
71+
. '<span title="' . htmlspecialchars($languageService->sL('LLL:EXT:recordlist/Resources/Private/Language/locallang.xlf:row.deletePlaceholder.title')) . '">'
72+
. htmlspecialchars($recTitle)
73+
. '</span>';
74+
} else {
75+
$theData[$fCol] = $theData['__label'] = $warning . $this->linkWrapItems($table, $row['uid'], $recTitle, $row);
76+
}
77+
78+
if ($thumbnailField) {
79+
$fullRow = isset($row[$thumbnailField]) ? $row : BackendUtility::getRecord($table, $row['uid']);
80+
81+
$thumbCode = '<br />' . BackendUtility::thumbCode($fullRow, $table, $thumbnailField);
82+
$theData[$fCol] .= $thumbCode;
83+
$theData['__label'] .= $thumbCode;
84+
}
85+
} elseif ($fCol === 'pid') {
86+
$theData[$fCol] = $row[$fCol];
87+
} elseif ($fCol !== '' && $fCol === ($GLOBALS['TCA'][$table]['ctrl']['cruser_id'] ?? '')) {
88+
$theData[$fCol] = $this->getBackendUserInformation((int)$row[$fCol]);
89+
} elseif ($fCol === '_SELECTOR_') {
90+
if ($table !== 'pages' || !$this->showOnlyTranslatedRecords) {
91+
// Add checkbox for all tables except the special page translations table
92+
$theData[$fCol] = $this->makeCheckbox($table, $row);
93+
} else {
94+
// Remove "_SELECTOR_", which is always the first item, from the field list
95+
array_splice($this->fieldArray, 0, 1);
96+
}
97+
} elseif ($fCol === 'icon') {
98+
$iconImg = '
99+
<span ' . BackendUtility::getRecordToolTip($row, $table) . ' ' . ($indent ? ' style="margin-left: ' . $indent . 'px;"' : '') . '>
100+
' . $this->iconFactory->getIconForRecord($table, $row, Icon::SIZE_SMALL)->render() . '
101+
</span>';
102+
$theData[$fCol] = ($this->clickMenuEnabled && !$this->isRecordDeletePlaceholder($row)) ? BackendUtility::wrapClickMenuOnIcon($iconImg, $table, $row['uid']) : $iconImg;
103+
} elseif ($fCol === '_PATH_') {
104+
$theData[$fCol] = $this->recPath($row['pid']);
105+
} elseif ($fCol === '_REF_') {
106+
$theData[$fCol] = $this->generateReferenceToolTip($table, $row['uid']);
107+
} elseif ($fCol === '_CONTROL_') {
108+
$theData[$fCol] = $this->makeControl($table, $row);
109+
} elseif ($fCol === '_LOCALIZATION_') {
110+
// Language flag an title
111+
$theData[$fCol] = $this->languageFlag($table, $row);
112+
// Localize record
113+
$localizationPanel = $translationEnabled ? $this->makeLocalizationPanel($table, $row, $translations) : '';
114+
if ($localizationPanel !== '') {
115+
$theData['_LOCALIZATION_b'] = '<div class="btn-group">' . $localizationPanel . '</div>';
116+
$this->showLocalizeColumn[$table] = true;
117+
}
118+
} elseif ($fCol !== '_LOCALIZATION_b') {
119+
// default for all other columns, except "_LOCALIZATION_b"
120+
$pageId = $table === 'pages' ? $row['uid'] : $row['pid'];
121+
$tmpProc = BackendUtility::getProcessedValueExtra($table, $fCol, $row[$fCol], 100, $row['uid'], true, $pageId);
122+
$theData[$fCol] = $this->linkUrlMail(htmlspecialchars((string)$tmpProc), (string)($row[$fCol] ?? ''));
123+
}
124+
}
125+
// Reset the ID if it was overwritten
126+
if ((string)$this->searchString !== '') {
127+
$this->id = $id_orig;
128+
}
129+
// Add classes to table cells
130+
$this->addElement_tdCssClass['_SELECTOR_'] = 'col-selector';
131+
$this->addElement_tdCssClass[$titleCol] = 'col-title col-responsive' . $deletePlaceholderClass;
132+
$this->addElement_tdCssClass['__label'] = $this->addElement_tdCssClass[$titleCol];
133+
$this->addElement_tdCssClass['icon'] = 'col-icon';
134+
$this->addElement_tdCssClass['_CONTROL_'] = 'col-control';
135+
$this->addElement_tdCssClass['_PATH_'] = 'col-path';
136+
$this->addElement_tdCssClass['_LOCALIZATION_'] = 'col-localizationa';
137+
$this->addElement_tdCssClass['_LOCALIZATION_b'] = 'col-localizationb';
138+
// Create element in table cells:
139+
$theData['uid'] = $row['uid'];
140+
if (isset($GLOBALS['TCA'][$table]['ctrl']['languageField'])
141+
&& isset($GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'])
142+
) {
143+
$theData['_l10nparent_'] = $row[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']];
144+
}
145+
146+
$tagAttributes = array_map(
147+
static function ($attributeValue) {
148+
if (is_array($attributeValue)) {
149+
return implode(' ', $attributeValue);
150+
}
151+
return $attributeValue;
152+
},
153+
$tagAttributes
154+
);
155+
156+
$rowOutput .= $this->addElement($theData, GeneralUtility::implodeAttributes($tagAttributes, true));
157+
// Finally, return table row element:
158+
return $rowOutput;
159+
}
160+
161+
protected function getThumbnailField(string $tableName): string
162+
{
163+
return GeneralUtility::makeInstance(Configuration::class)->getField($tableName);
164+
}
165+
}

0 commit comments

Comments
 (0)