You are here

public function JsonapiHelper::extractEntity in Entity Share 8

Same name and namespace in other branches
  1. 8.3 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.

TODO: Should this method be removed from the interface?

Parameters

array $data: An array of data.

Return value

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

Overrides JsonapiHelperInterface::extractEntity

1 call to JsonapiHelper::extractEntity()
JsonapiHelper::importEntityListData in modules/entity_share_client/src/Service/JsonapiHelper.php
Use data from the JSONAPI to import content.

File

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

Class

JsonapiHelper
Class JsonapiHelper.

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'],
    ],
  ];
  $parsed_type = explode('--', $data['type']);
  return $this->jsonapiDocumentTopLevelNormalizer
    ->denormalize($prepared_json, NULL, 'api_json', [
    'resource_type' => $this->resourceTypeRepository
      ->get($parsed_type[0], $parsed_type[1]),
  ]);
}