Skip to content

Commit

Permalink
Merge pull request #1 from maikschneider/feature/v11
Browse files Browse the repository at this point in the history
TYPO3 v11 support
  • Loading branch information
jackd248 authored Sep 7, 2023
2 parents 244b5ef + 4bedc6e commit ab450b4
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 85 deletions.
78 changes: 78 additions & 0 deletions Classes/Domain/Model/Dto/ListItem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

namespace Xima\XimaRecentUpdatesWidget\Domain\Model\Dto;

use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;

class ListItem
{
public array $log = [];

public static function createFromV11Log(array $sysLogRow): static
{
$item = new static();
$item->log = $sysLogRow;
$item->log['log_data'] = unserialize($item->log['log_data']);
$item->log['title'] = $item->log['log_data'][0] ?? '';
return $item;
}

public static function createFromV12Log(array $sysLogRow): static
{
$item = new static();
$item->log = $sysLogRow;
$item->log['log_data'] = json_decode($item->log['log_data'], true);
$item->log['title'] = $item->log['log_data']['title'] ?? '';
return $item;
}

public function getDetails(): string
{
return str_replace(['{', '}'], '', str_replace(array_keys($this->log['log_data']), $this->log['log_data'], $this->log['details']));
}

public function getType(): string
{
$table = $this->log['tablename'];
$cType = $this->log['cType'];

if ($table !== 'tt_content' || $cType === '') {
return $table;
} elseif ($cType === 'list') {
return $this->log['listType'];
} else {
$label = '';
$CTypeLabels = [];
$contentGroups = BackendUtility::getPagesTSconfig($this->log['pageId'])['mod.']['wizards.']['newContentElement.']['wizardItems.'] ?? [];
foreach ($contentGroups as $group) {
foreach ($group['elements.'] as $element) {
$CTypeLabels[$element['tt_content_defValues.']['CType']] = $element['title'];
}
}
if (isset($CTypeLabels[$cType])) {
$label = $CTypeLabels[$cType];
}
return LocalizationUtility::translate($label);
}
}

public function getTitle(): string
{
return self::truncate($this->log['title'] ?? '');
}

public static function truncate(string $string, int $length=50, string $append='&hellip;'): string
{
$string = trim($string);

if (strlen($string) > $length) {
$string = wordwrap($string, $length);
$string = explode("\n", $string, 2);
$string = $string[0] . $append;
}

return $string;
}

}
66 changes: 7 additions & 59 deletions Classes/Widgets/Provider/RecentUpdatesDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

namespace Xima\XimaRecentUpdatesWidget\Widgets\Provider;

use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Dashboard\Widgets\ListDataProviderInterface;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
use Xima\XimaRecentUpdatesWidget\Domain\Model\Dto\ListItem;

class RecentUpdatesDataProvider implements ListDataProviderInterface
{
Expand All @@ -17,9 +17,10 @@ class RecentUpdatesDataProvider implements ListDataProviderInterface
*/
public function getItems(): array
{
$typo3Version = GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion();
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_log');

$results = $queryBuilder
$results = $queryBuilder
->select(
'sl.recuid as uid',
'sl.tstamp as updated',
Expand All @@ -46,65 +47,12 @@ public function getItems(): array
$items = [];

foreach ($results as $result) {
$logData = json_decode($result['log_data'], true);
$table = $logData['table'];

if ($table !== 'tt_content' || $result['cType'] === '') {
$type = $table;
} elseif ($result['cType'] === 'list') {
$type = $result['listType'];
} else {
$type = $this->getCTypeTranslationString($result['cType'], $result['pageId']);
try {
$items[] = $typo3Version === 11 ? ListItem::createFromV11Log($result) : ListItem::createFromV12Log($result);
} catch (\Exception $e) {
}

$items[] = [
'uid' => $result['uid'],
'title' => $this->truncate($logData['title']),
'table' => $logData['table'],
'pageId' => $result['pageId'],
'pageTitle' => $result['pageTitle'],
'type' => $type,
'updated' => $result['updated'],
'userName' => $result['username'],
'userId' => $result['userId'],
'details' => str_replace(['{', '}'], '', str_replace(array_keys($logData), $logData, $result['details'])),
];
}

return $items;
}

protected function getCTypeTranslationString(string $key, int $pid): string
{
$label = '';
$CTypeLabels = [];
$contentGroups = BackendUtility::getPagesTSconfig($pid)['mod.']['wizards.']['newContentElement.']['wizardItems.'] ?? [];
foreach ($contentGroups as $group) {
foreach ($group['elements.'] as $element) {
$CTypeLabels[$element['tt_content_defValues.']['CType']] = $element['title'];
}
}
if (isset($CTypeLabels[$key])) {
$label = $CTypeLabels[$key];
}

if (str_starts_with($label, 'LLL:')) {
$label = LocalizationUtility::translate($label);
}

return $label;
}

protected function truncate(string $string, int $length=50, string $append='&hellip;'): string
{
$string = trim($string);

if (strlen($string) > $length) {
$string = wordwrap($string, $length);
$string = explode("\n", $string, 2);
$string = $string[0] . $append;
}

return $string;
}
}
9 changes: 1 addition & 8 deletions Classes/Widgets/RecentUpdates.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Dashboard\Widgets\ButtonProviderInterface;
use TYPO3\CMS\Dashboard\Widgets\ListDataProviderInterface;
use TYPO3\CMS\Dashboard\Widgets\RequestAwareWidgetInterface;
use TYPO3\CMS\Dashboard\Widgets\WidgetConfigurationInterface;
use TYPO3\CMS\Dashboard\Widgets\WidgetInterface;
use TYPO3\CMS\Fluid\View\StandaloneView;

class RecentUpdates implements WidgetInterface, RequestAwareWidgetInterface
class RecentUpdates implements WidgetInterface
{
protected ServerRequestInterface $request;

Expand All @@ -35,7 +34,6 @@ public function renderWidgetContent(): string
$view->setTemplateRootPaths(['EXT:xima_recent_updates_widget/Resources/Private/Templates/']);
$view->setPartialRootPaths(['EXT:xima_recent_updates_widget/Resources/Private/Partials/']);
$view->setTemplatePathAndFilename($template);
$view->setRequest($this->request);

$view->assignMultiple([
'configuration' => $this->configuration,
Expand All @@ -50,9 +48,4 @@ public function getOptions(): array
{
return $this->options;
}

public function setRequest(ServerRequestInterface $request): void
{
$this->request = $request;
}
}
28 changes: 14 additions & 14 deletions Resources/Private/Partials/Item.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,35 @@

<tr>
<td>
<be:link.editRecord uid="{uid}"
table="{table}"
title="{details}"
<be:link.editRecord uid="{item.log.uid}"
table="{item.log.tablename}"
title="{item.details}"
returnUrl="{be:moduleLink(route: 'dashboard')}">
<core:iconForRecord table="{table}" row="{_all}"/>
<strong>{f:if(condition: title, then: '{title -> f:format.raw()}', else: '[{f:translate(key:
<core:iconForRecord table="{item.log.tablename}" row="{item.log}"/>
<strong>{f:if(condition: item.title, then: '{item.title -> f:format.raw()}', else: '[{f:translate(key:
\'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.no_title\')}]')}</strong>
</be:link.editRecord>
</td>
<td>
<f:if condition="{pageTitle} && {pageId}">
<a href="{be:moduleLink(route: 'web_layout', arguments: '{id: pageId}')}"
<f:if condition="{item.log.pageTitle} && {item.log.pageId}">
<a href="{be:moduleLink(route: 'web_layout', arguments: '{id: item.log.pageId}')}"
target="_blank"
title="">
<core:iconForRecord table="pages" row="{_all}"/>
{pageTitle}
<core:iconForRecord table="pages" row="{item.log}"/>
{item.log.pageTitle}
</a>
</f:if>
</td>
<td>
<core:iconForRecord table="{table}" row="{_all}"/>
{type}
<core:iconForRecord table="{item.log.tablename}" row="{item.log}"/>
{item.type}
</td>
<td>
<f:format.date format="d.m.Y H:i">{updated}</f:format.date>
<f:format.date format="d.m.Y H:i">{item.log.updated}</f:format.date>
</td>
<td class="x--recent-updates-widget--user" style="display: flex;gap: 10px;">
<backend:avatar backendUser="{userId}" size="20"/>
{userName}
<backend:avatar backendUser="{item.log.userId}" size="20"/>
{item.log.username}
</td>
</tr>

Expand Down
2 changes: 1 addition & 1 deletion Resources/Private/Templates/List.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</thead>
<tbody>
<f:for each="{records}" as="record">
<f:render partial="Item" arguments="{record}"/>
<f:render partial="Item" arguments="{item: record}"/>
</f:for>
</tbody>
</table>
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
}
],
"require": {
"typo3/cms-backend": "^12.0",
"typo3/cms-core": "^12.0",
"typo3/cms-dashboard": "^12.0"
"typo3/cms-backend": "^11.5 || ^12.0",
"typo3/cms-core": "^11.5 || ^12.0",
"typo3/cms-dashboard": "^11.5 || ^12.0"
},
"autoload": {
"psr-4": {
Expand Down

0 comments on commit ab450b4

Please sign in to comment.