If I access a paragraph entity trough JSON:API (/jsonapi/paragraph/author) that has a Text or Entity field I get this error:
Error: Call to a member function getTypeName() on boolean in Drupal\jsonapi\JsonApiResource\ResourceIdentifier->__construct() (line 83 of /app/htdocs/core/modules/jsonapi/src/JsonApiResource/ResourceIdentifier.php)
#0 /app/htdocs/core/modules/jsonapi/src/JsonApiResource/ResourceIdentifier.php(458): Drupal\jsonapi\JsonApiResource\ResourceIdentifier->__construct(false, 'missing', Array)
#1 /app/htdocs/core/modules/jsonapi/src/JsonApiResource/ResourceIdentifier.php(286): Drupal\jsonapi\JsonApiResource\ResourceIdentifier::getVirtualOrMissingResourceIdentifier(Object(Drupal\text_or_entity\Plugin\Field\FieldType\TextOrEntityReferenceItem))
#2 /app/htdocs/core/modules/jsonapi/src/JsonApiResource/ResourceIdentifier.php(319): Drupal\jsonapi\JsonApiResource\ResourceIdentifier::toResourceIdentifier(Object(Drupal\text_or_entity\Plugin\Field\FieldType\TextOrEntityReferenceItem))
#3 /app/htdocs/core/modules/jsonapi/src/JsonApiResource/Relationship.php(123): Drupal\jsonapi\JsonApiResource\ResourceIdentifier::toResourceIdentifiers(Object(Drupal\text_or_entity\Plugin\Field\TextOrEntityReferenceFieldItemList))
#4 /app/htdocs/core/modules/jsonapi/src/Normalizer/ResourceObjectNormalizer.php(186): Drupal\jsonapi\JsonApiResource\Relationship::createFromEntityReferenceField(Object(Drupal\jsonapi\JsonApiResource\ResourceObject), Object(Drupal\text_or_entity\Plugin\Field\TextOrEntityReferenceFieldItemList))
#5 /app/htdocs/core/modules/jsonapi/src/Normalizer/ResourceObjectNormalizer.php(121): Drupal\jsonapi\Normalizer\ResourceObjectNormalizer->serializeField(Object(Drupal\text_or_entity\Plugin\Field\TextOrEntityReferenceFieldItemList), Array, 'api_json')
#6 /app/htdocs/core/modules/jsonapi/src/Normalizer/ResourceObjectNormalizer.php(73): Drupal\jsonapi\Normalizer\ResourceObjectNormalizer->getNormalization(Array, Object(Drupal\jsonapi\JsonApiResource\ResourceObject), 'api_json', Array)
#7 /app/vendor/symfony/serializer/Serializer.php(143): Drupal\jsonapi\Normalizer\ResourceObjectNormalizer->normalize(Object(Drupal\jsonapi\JsonApiResource\ResourceObject), 'api_json', Array)
#8 /app/htdocs/core/modules/jsonapi/src/Serializer/Serializer.php(62): Symfony\Component\Serializer\Serializer->normalize(Object(Drupal\jsonapi\JsonApiResource\ResourceObject), 'api_json', Array)
#9 /app/htdocs/core/modules/jsonapi/src/Normalizer/DataNormalizer.php(26): Drupal\jsonapi\Serializer\Serializer->normalize(Object(Drupal\jsonapi\JsonApiResource\ResourceObject), 'api_json', Array)
#10 [internal function]: Drupal\jsonapi\Normalizer\DataNormalizer->Drupal\jsonapi\Normalizer\{closure}(Object(Drupal\jsonapi\JsonApiResource\ResourceObject))
#11 /app/htdocs/core/modules/jsonapi/src/Normalizer/DataNormalizer.php(27): array_map(Object(Closure), Array)
#12 /app/vendor/symfony/serializer/Serializer.php(143): Drupal\jsonapi\Normalizer\DataNormalizer->normalize(Object(Drupal\jsonapi\JsonApiResource\ResourceObjectData), 'api_json', Array)
#13 /app/htdocs/core/modules/jsonapi/src/Serializer/Serializer.php(62): Symfony\Component\Serializer\Serializer->normalize(Object(Drupal\jsonapi\JsonApiResource\ResourceObjectData), 'api_json', Array)
#14 /app/htdocs/core/modules/jsonapi/src/Normalizer/JsonApiDocumentTopLevelNormalizer.php(191): Drupal\jsonapi\Serializer\Serializer->normalize(Object(Drupal\jsonapi\JsonApiResource\ResourceObjectData), 'api_json', Array)
#15 /app/vendor/symfony/serializer/Serializer.php(143): Drupal\jsonapi\Normalizer\JsonApiDocumentTopLevelNormalizer->normalize(Object(Drupal\jsonapi\JsonApiResource\JsonApiDocumentTopLevel), 'api_json', Array)
#16 /app/htdocs/core/modules/jsonapi/src/Serializer/Serializer.php(62): Symfony\Component\Serializer\Serializer->normalize(Object(Drupal\jsonapi\JsonApiResource\JsonApiDocumentTopLevel), 'api_json', Array)
#17 /app/htdocs/core/modules/jsonapi/src/EventSubscriber/ResourceResponseSubscriber.php(120): Drupal\jsonapi\Serializer\Serializer->normalize(Object(Drupal\jsonapi\JsonApiResource\JsonApiDocumentTopLevel), 'api_json', Array)
#18 /app/htdocs/core/modules/jsonapi/src/EventSubscriber/ResourceResponseSubscriber.php(85): Drupal\jsonapi\EventSubscriber\ResourceResponseSubscriber->renderResponseBody(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\jsonapi\ResourceResponse), Object(Drupal\jsonapi\Serializer\Serializer), 'api_json')
#19 [internal function]: Drupal\jsonapi\EventSubscriber\ResourceResponseSubscriber->onResponse(Object(Symfony\Component\HttpKernel\Event\FilterResponseEvent), 'kernel.response', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#20 /app/htdocs/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func(Array, Object(Symfony\Component\HttpKernel\Event\FilterResponseEvent), 'kernel.response', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#21 /app/vendor/symfony/http-kernel/HttpKernel.php(191): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.response', Object(Symfony\Component\HttpKernel\Event\FilterResponseEvent))
#22 /app/vendor/symfony/http-kernel/HttpKernel.php(173): Symfony\Component\HttpKernel\HttpKernel->filterResponse(Object(Drupal\jsonapi\ResourceResponse), Object(Symfony\Component\HttpFoundation\Request), 1)
#23 /app/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#24 /app/htdocs/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#25 /app/htdocs/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#26 /app/htdocs/core/modules/page_cache/src/StackMiddleware/PageCache.php(191): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#27 /app/htdocs/core/modules/page_cache/src/StackMiddleware/PageCache.php(128): Drupal\page_cache\StackMiddleware\PageCache->fetch(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#28 /app/htdocs/core/modules/page_cache/src/StackMiddleware/PageCache.php(82): Drupal\page_cache\StackMiddleware\PageCache->lookup(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#29 /app/htdocs/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#30 /app/htdocs/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#31 /app/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#32 /app/htdocs/core/lib/Drupal/Core/DrupalKernel.php(694): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#33 /app/htdocs/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#34 {main}
Comments
Comment #2
czigor commentedAttached patch adds a jsonapi_extras field enhancer. To use it:
1. Enable jsonapi_extras
2. Go to /admin/config/services/jsonapi/resource_types
3. Enable the "Text or Entity Reference Field" field enhancer for every text_or_entity_reference field
Comment #4
czigor commentedCommitted this. Let me know if there's a better solution (without using json_extras, for example).
Comment #5
introfini commentedThank you András for such a quick response!
I think it's ok like that, because: