ResourceTypeConverter.php in JSON:API 8
File
src/ParamConverter/ResourceTypeConverter.php
View source
<?php
namespace Drupal\jsonapi\ParamConverter;
use Drupal\Core\ParamConverter\ParamConverterInterface;
use Drupal\jsonapi\ResourceType\ResourceTypeRepositoryInterface;
use Symfony\Component\Routing\Route;
class ResourceTypeConverter implements ParamConverterInterface {
const PARAM_TYPE_ID = 'jsonapi_resource_type';
protected $resourceTypeRepository;
public function __construct(ResourceTypeRepositoryInterface $resource_type_repository) {
$this->resourceTypeRepository = $resource_type_repository;
}
public function convert($value, $definition, $name, array $defaults) {
return $this->resourceTypeRepository
->getByTypeName($value);
}
public function applies($definition, $name, Route $route) {
return !empty($definition['type']) && $definition['type'] === static::PARAM_TYPE_ID;
}
}