class ResourceTypeConverter in JSON:API 8
Same name and namespace in other branches
- 8.2 src/ParamConverter/ResourceTypeConverter.php \Drupal\jsonapi\ParamConverter\ResourceTypeConverter
Parameter converter for upcasting JSON API resource type names to objects.
@internal
Hierarchy
- class \Drupal\jsonapi\ParamConverter\ResourceTypeConverter implements ParamConverterInterface
Expanded class hierarchy of ResourceTypeConverter
1 file declares its use of ResourceTypeConverter
- Routes.php in src/
Routing/ Routes.php
1 string reference to 'ResourceTypeConverter'
1 service uses ResourceTypeConverter
File
- src/
ParamConverter/ ResourceTypeConverter.php, line 14
Namespace
Drupal\jsonapi\ParamConverterView source
class ResourceTypeConverter implements ParamConverterInterface {
/**
* The route parameter type to match.
*
* @var string
*/
const PARAM_TYPE_ID = 'jsonapi_resource_type';
/**
* The JSON API resource type repository.
*
* @var \Drupal\jsonapi\ResourceType\ResourceTypeRepositoryInterface
*/
protected $resourceTypeRepository;
/**
* ResourceTypeConverter constructor.
*
* @param \Drupal\jsonapi\ResourceType\ResourceTypeRepositoryInterface $resource_type_repository
* The JSON API resource type repository.
*/
public function __construct(ResourceTypeRepositoryInterface $resource_type_repository) {
$this->resourceTypeRepository = $resource_type_repository;
}
/**
* {@inheritdoc}
*/
public function convert($value, $definition, $name, array $defaults) {
return $this->resourceTypeRepository
->getByTypeName($value);
}
/**
* {@inheritdoc}
*/
public function applies($definition, $name, Route $route) {
return !empty($definition['type']) && $definition['type'] === static::PARAM_TYPE_ID;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ResourceTypeConverter:: |
protected | property | The JSON API resource type repository. | |
ResourceTypeConverter:: |
public | function |
Determines if the converter applies to a specific route and variable. Overrides ParamConverterInterface:: |
|
ResourceTypeConverter:: |
public | function |
Converts path variables to their corresponding objects. Overrides ParamConverterInterface:: |
|
ResourceTypeConverter:: |
constant | The route parameter type to match. | ||
ResourceTypeConverter:: |
public | function | ResourceTypeConverter constructor. |