You are here

public function JsonapiHelper::extractEntity in Entity Share 8.3

Same name and namespace in other branches
  1. 8 modules/entity_share_client/src/Service/JsonapiHelper.php \Drupal\entity_share_client\Service\JsonapiHelper::extractEntity()
  2. 8.2 modules/entity_share_client/src/Service/JsonapiHelper.php \Drupal\entity_share_client\Service\JsonapiHelper::extractEntity()

Helper function to unserialize an entity from the JSON:API response.

Parameters

array $data: An array of data.

Return value

\Drupal\Core\Entity\EntityInterface An unserialize entity.

Overrides JsonapiHelperInterface::extractEntity

File

modules/entity_share_client/src/Service/JsonapiHelper.php, line 58

Class

JsonapiHelper
Provides methods not present in the JSON:API module.

Namespace

Drupal\entity_share_client\Service

Code

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']),
  ]);
}