Hello,
I was testing Entity share, with the last JSONAPI, JSONAPI Extras (branch 8.x-2.x) and Entity share code bases.
When denormalizing JSONAPI results, to display the contents to import, the AJAX request fails and here is the stacktrace:
The website encountered an unexpected error. Please try again later.Symfony\Component\Serializer\Exception\UnexpectedValueException: Could not determine entity type bundle: "type" field is missing. in Drupal\serialization\Normalizer\EntityNormalizer->extractBundleData() (line 98 of core/modules/serialization/src/Normalizer/FieldableEntityNormalizerTrait.php).
Drupal\serialization\Normalizer\EntityNormalizer->denormalize(Array, 'Drupal\node\Entity\Node', 'api_json', Array) (Line: 182) Symfony\Component\Serializer\Serializer->denormalize(Array, 'Drupal\node\Entity\Node', 'api_json', Array) (Line: 189) Drupal\jsonapi\Normalizer\JsonApiDocumentTopLevelNormalizer->denormalize(Array, 'Drupal\node\Entity\Node', 'api_json', Array) (Line: 427) Drupal\entity_share_client\Service\JsonapiHelper->addOptionFromJson(Array, Array) (Line: 190) Drupal\entity_share_client\Service\JsonapiHelper->buildEntitiesOptions(Array) (Line: 481) Drupal\entity_share_client\Form\PullForm->buildEntitiesSelectTable(Array, Object) (Line: 365) Drupal\entity_share_client\Form\PullForm->buildChannelSelect(Array, Object) (Line: 162) Drupal\entity_share_client\Form\PullForm->buildForm(Array, Object) call_user_func_array(Array, Array) (Line: 514) Drupal\Core\Form\FormBuilder->retrieveForm('entity_share_client_pull_form', Object) (Line: 364) Drupal\Core\Form\FormBuilder->rebuildForm('entity_share_client_pull_form', Object, Array) (Line: 621) Drupal\Core\Form\FormBuilder->processForm('entity_share_client_pull_form', Array, Object) (Line: 314) Drupal\Core\Form\FormBuilder->buildForm('entity_share_client_pull_form', Object) (Line: 74) Drupal\Core\Controller\FormController->getContentResult(Object, Object) call_user_func_array(Array, Array) (Line: 123) Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 582) Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124) Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97) Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 151) Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68) Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57) Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47) Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99) Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78) Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 40) Drupal\jsonapi\StackMiddleware\FormatSetter->handle(Object, 1, 1) (Line: 47) Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50) Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23) Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 657) Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
The problem is in https://cgit.drupalcode.org/entity_share/tree/modules/entity_share_clien...
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->jsonapiSerializer->denormalize($prepared_json, JsonApiDocumentTopLevelNormalizer::class, 'api_json', [
'resource_type' => $this->resourceTypeRepository->get(
$parsed_type[0],
$parsed_type[1]
),
]);
$this->addOption($options, $entity, $parsed_type[0], $parsed_type[1], $level);
}
The denormalization does not work any more. I tried to see the evolutions of JsonApiDocumentTopLevelNormalizerTest::testDenormalize() but I can't figure out how to solve that.
Also if Entity share can stop relying on any JSONAPI internal services, that would be really helpful.
Thanks for any help.
Comments
Comment #2
e0ipsoAny chance you can do a
git bisector similar to find out what commit broke this functionality?Comment #3
grimreaperThanks for the reply.
Yep. The result gives me this commit: https://cgit.drupalcode.org/jsonapi/commit/?id=b764e0e084cb82597dd076ce0...
On this commit, I have been able to update Entity share code to follow the changes.
But on the last dev version of JSONAPI I have another problem.
I am checking what is it.
Comment #4
grimreaperOk. Found it.
In 'relationships', the links are now always present even if there is no data.
Adding a small check.
Will credit you in the commit.
Comment #5
wim leers👍