You are here

protected function JsonapiHelper::addOptionFromJson in Entity Share 8

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

Helper function to add an option.

Parameters

array $options: The array of options for the tableselect form type element.

array $data: An array of data.

int $level: The level of indentation.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\InvalidArgumentException

1 call to JsonapiHelper::addOptionFromJson()
JsonapiHelper::buildEntitiesOptions in modules/entity_share_client/src/Service/JsonapiHelper.php
Prepare entities from an URI to request.

File

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

Class

JsonapiHelper
Class JsonapiHelper.

Namespace

Drupal\entity_share_client\Service

Code

protected function addOptionFromJson(array &$options, array $data, $level = 0) {

  // Format JSON as in
  // JsonApiDocumentTopLevelNormalizerTest::testDenormalize().
  $prepared_json = [
    'data' => [
      'type' => $data['type'],
      'attributes' => $data['attributes'],
    ],
  ];
  $parsed_type = explode('--', $data['type']);

  /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
  $entity = $this->jsonapiDocumentTopLevelNormalizer
    ->denormalize($prepared_json, NULL, 'api_json', [
    'resource_type' => $this->resourceTypeRepository
      ->get($parsed_type[0], $parsed_type[1]),
  ]);
  $this
    ->addOption($options, $entity, $parsed_type[0], $parsed_type[1], $level);
}