class JsonapiHelper in Entity Share 8.3
Same name and namespace in other branches
- 8 modules/entity_share_client/src/Service/JsonapiHelper.php \Drupal\entity_share_client\Service\JsonapiHelper
- 8.2 modules/entity_share_client/src/Service/JsonapiHelper.php \Drupal\entity_share_client\Service\JsonapiHelper
Provides methods not present in the JSON:API module.
@package Drupal\entity_share_client\Service
Hierarchy
- class \Drupal\entity_share_client\Service\JsonapiHelper implements JsonapiHelperInterface uses StringTranslationTrait
Expanded class hierarchy of JsonapiHelper
1 string reference to 'JsonapiHelper'
- entity_share_client.services.yml in modules/
entity_share_client/ entity_share_client.services.yml - modules/entity_share_client/entity_share_client.services.yml
1 service uses JsonapiHelper
- entity_share_client.jsonapi_helper in modules/
entity_share_client/ entity_share_client.services.yml - Drupal\entity_share_client\Service\JsonapiHelper
File
- modules/
entity_share_client/ src/ Service/ JsonapiHelper.php, line 17
Namespace
Drupal\entity_share_client\ServiceView source
class JsonapiHelper implements JsonapiHelperInterface {
use StringTranslationTrait;
/**
* The JsonApiDocumentTopLevelNormalizer normalizer.
*
* @var \Drupal\jsonapi\Normalizer\JsonApiDocumentTopLevelNormalizer
*/
protected $jsonapiDocumentTopLevelNormalizer;
/**
* The resource type repository.
*
* @var \Drupal\jsonapi\ResourceType\ResourceTypeRepositoryInterface
*/
protected $resourceTypeRepository;
/**
* JsonapiHelper constructor.
*
* @param \Symfony\Component\Serializer\SerializerInterface $serializer
* A serializer.
* @param \Drupal\jsonapi\Normalizer\JsonApiDocumentTopLevelNormalizer $jsonapi_document_top_level_normalizer
* The JsonApiDocumentTopLevelNormalizer normalizer.
* @param \Drupal\jsonapi\ResourceType\ResourceTypeRepositoryInterface $resource_type_repository
* The resource type repository.
*/
public function __construct(SerializerInterface $serializer, JsonApiDocumentTopLevelNormalizer $jsonapi_document_top_level_normalizer, ResourceTypeRepositoryInterface $resource_type_repository) {
$this->jsonapiDocumentTopLevelNormalizer = $jsonapi_document_top_level_normalizer;
$this->jsonapiDocumentTopLevelNormalizer
->setSerializer($serializer);
$this->resourceTypeRepository = $resource_type_repository;
}
/**
* {@inheritdoc}
*/
public function extractEntity(array $data) {
// Format JSON as in
// JsonApiDocumentTopLevelNormalizerTest::testDenormalize().
$prepared_json = [
'data' => [
'type' => $data['type'],
'attributes' => $data['attributes'],
],
];
return $this->jsonapiDocumentTopLevelNormalizer
->denormalize($prepared_json, NULL, 'api_json', [
'resource_type' => $this->resourceTypeRepository
->getByTypeName($data['type']),
]);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
JsonapiHelper:: |
protected | property | The JsonApiDocumentTopLevelNormalizer normalizer. | |
JsonapiHelper:: |
protected | property | The resource type repository. | |
JsonapiHelper:: |
public | function |
Helper function to unserialize an entity from the JSON:API response. Overrides JsonapiHelperInterface:: |
|
JsonapiHelper:: |
public | function | JsonapiHelper constructor. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |