Problem/Motivation
While working on a headless drupal site, we are using this field and when we submit data from frontend I always get the below error -
Error: Call to a member function getClass() on null in Drupal\hal\Normalizer\FieldItemNormalizer->constructValue() (line 242 of /app/web/core/modules/serialization/src/Normalizer/FieldableEntityNormalizerTrait.php)
#0 /app/web/core/modules/hal/src/Normalizer/FieldItemNormalizer.php(62): Drupal\hal\Normalizer\FieldItemNormalizer->constructValue(true, Array)
#1 /app/vendor/symfony/serializer/Serializer.php(182): Drupal\hal\Normalizer\FieldItemNormalizer->denormalize(true, 'Drupal\\mailchim...', 'hal_json', Array)
#2 /app/web/core/modules/serialization/src/Normalizer/FieldNormalizer.php(52): Symfony\Component\Serializer\Serializer->denormalize(true, 'Drupal\\mailchim...', 'hal_json', Array)
#3 /app/vendor/symfony/serializer/Serializer.php(182): Drupal\serialization\Normalizer\FieldNormalizer->denormalize(Array, 'Drupal\\Core\\Fie...', 'hal_json', Array)
#4 /app/web/core/modules/serialization/src/Normalizer/FieldableEntityNormalizerTrait.php(151): Symfony\Component\Serializer\Serializer->denormalize(Array, 'Drupal\\Core\\Fie...', 'hal_json', Array)
#5 /app/web/core/modules/hal/src/Normalizer/ContentEntityNormalizer.php(195): Drupal\hal\Normalizer\ContentEntityNormalizer->denormalizeFieldData(Array, Object(Drupal\user\Entity\User), 'hal_json', Array)
#6 /app/vendor/symfony/serializer/Serializer.php(182): Drupal\hal\Normalizer\ContentEntityNormalizer->denormalize(Array, 'Drupal\\user\\Ent...', 'hal_json', Array)
#7 /app/web/core/modules/rest/src/RequestHandler.php(196): Symfony\Component\Serializer\Serializer->denormalize(Array, 'Drupal\\user\\Ent...', 'hal_json', Array)
#8 /app/web/core/modules/rest/src/RequestHandler.php(79): Drupal\rest\RequestHandler->deserialize(Object(Drupal\Core\Routing\RouteMatch), Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\cg_auth\Plugin\rest\resource\UserRegistrationResource))
#9 [internal function]: Drupal\rest\RequestHandler->handle(Object(Drupal\Core\Routing\RouteMatch), Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\rest\Entity\RestResourceConfig))
#10 /app/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#11 /app/web/core/lib/Drupal/Core/Render/Renderer.php(573): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#12 /app/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
Steps to reproduce
Add the field to user entity and create a new entity using api.
Proposed resolution
We implement mainPropertyName
method in the MailchimpListsSubscription class and return 'subscribe'.