Skip to content

Commit

Permalink
chore!: move file references logic from trait to helper class
Browse files Browse the repository at this point in the history
  • Loading branch information
smichaelsen committed Sep 5, 2024
1 parent 5106ba6 commit 9529fe3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 37 deletions.
40 changes: 40 additions & 0 deletions Classes/DataProviding/Helpers/FileReferencesHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

namespace Sinso\Webcomponents\DataProviding\Helpers;

use TYPO3\CMS\Core\Resource\FileReference;
use TYPO3\CMS\Core\Resource\FileRepository;

class FileReferencesHelper
{
public function __construct(
private readonly FileRepository $fileRepository,
) {}

/**
* @param array<string, string|int> $record
* @return array<FileReference>
*/
public function loadFileReferences(array $record, string $fieldName, string $localTableName = 'tt_content'): array
{
$localUid = $record['_LOCALIZED_UID'] ?? $record['uid'] ?? null;
if (empty($localUid)) {
return [];
}
return $this->fileRepository->findByRelation($localTableName, $fieldName, (int)$localUid);
}

/**
* @param array<string, string|int> $record
*/
public function loadFileReference(array $record, string $fieldName, string $localTableName = 'tt_content'): ?FileReference
{
$fileReferences = $this->loadFileReferences($record, $fieldName, $localTableName);
if (empty($fileReferences)) {
return null;
}
return $fileReferences[0];
}
}
37 changes: 0 additions & 37 deletions Classes/DataProviding/Traits/FileReferences.php

This file was deleted.

0 comments on commit 9529fe3

Please sign in to comment.