class ResourceTypeConverter
Same name in other branches
- 8.9.x core/modules/jsonapi/src/ParamConverter/ResourceTypeConverter.php \Drupal\jsonapi\ParamConverter\ResourceTypeConverter
- 10 core/modules/jsonapi/src/ParamConverter/ResourceTypeConverter.php \Drupal\jsonapi\ParamConverter\ResourceTypeConverter
- 11.x core/modules/jsonapi/src/ParamConverter/ResourceTypeConverter.php \Drupal\jsonapi\ParamConverter\ResourceTypeConverter
Parameter converter for upcasting JSON:API resource type names to objects.
@internal JSON:API maintains no PHP API since its API is the HTTP API. This class may change at any time and this will break any dependencies on it.
Hierarchy
- class \Drupal\jsonapi\ParamConverter\ResourceTypeConverter implements \Drupal\Core\ParamConverter\ParamConverterInterface
Expanded class hierarchy of ResourceTypeConverter
See also
https://www.drupal.org/project/drupal/issues/3032787
1 file declares its use of ResourceTypeConverter
- Routes.php in core/
modules/ jsonapi/ src/ Routing/ Routes.php
1 string reference to 'ResourceTypeConverter'
- jsonapi.services.yml in core/
modules/ jsonapi/ jsonapi.services.yml - core/modules/jsonapi/jsonapi.services.yml
1 service uses ResourceTypeConverter
File
-
core/
modules/ jsonapi/ src/ ParamConverter/ ResourceTypeConverter.php, line 18
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
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
ResourceTypeConverter::$resourceTypeRepository | protected | property | The JSON:API resource type repository. | |
ResourceTypeConverter::applies | public | function | Determines if the converter applies to a specific route and variable. | Overrides ParamConverterInterface::applies |
ResourceTypeConverter::convert | public | function | Converts path variables to their corresponding objects. | Overrides ParamConverterInterface::convert |
ResourceTypeConverter::PARAM_TYPE_ID | constant | The route parameter type to match. | ||
ResourceTypeConverter::__construct | public | function | ResourceTypeConverter constructor. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.