Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore!: move file references logic from trait to helper class #36

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading