Files
crowd-fund-api/src/State/ThemeStateProvider.php
T
daniel.subiabre ac47aec378 feat: Themes (#257)
* feat: add trait to unify get by id or slug logic

* feat: add Theme resource

* fix: categories and themes

* feat: update api docs for projects to themes relationship

* feat: update doctrine relationship of projects to themes

* feat: add v3 categories to v4 themes pumping during projects pumping
2026-10-08 13:02:07 +02:00

34 lines
986 B
PHP

<?php
namespace App\State;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProviderInterface;
use App\ApiResource\ThemeApiResource;
use App\Doctrine\LocalizedExtensionTrait;
use App\Mapping\AutoMapper;
use App\Repository\ThemeRepository;
class ThemeStateProvider implements ProviderInterface
{
use LocalizedExtensionTrait;
public function __construct(
private ThemeRepository $themeRepository,
private AutoMapper $autoMapper,
) {}
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
{
$queryBuilder = $this->themeRepository->getByIdOrSlugQuery($uriVariables['idOrSlug']);
$query = $this->addLocalizationHints($queryBuilder, $this->getAcceptedLanguages($context));
$theme = $query->getOneOrNullResult();
if ($theme === null) {
return null;
}
return $this->autoMapper->map($theme, ThemeApiResource::class);
}
}