-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore!: move file references logic from trait to helper class
- Loading branch information
1 parent
5106ba6
commit 9529fe3
Showing
2 changed files
with
40 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.