Error: Call to a member function isNew() on null in Drupal\Core\Entity\Plugin\Validation\Constraint\ValidReferenceConstraintValidator->validate()

Created on 29 September 2020, about 4 years ago
Updated 22 November 2023, about 1 year ago

i made a custom field, widget and formatter and i get this error when ajax add more or saving the entity form.
How do i provide an entity that may not exist yet to the validator?

Error: Call to a member function isNew() on null in Drupal\Core\Entity\Plugin\Validation\Constraint\ValidReferenceConstraintValidator->validate() (line 74 of /var/www/html/core/lib/Drupal/Core/Entity/Plugin/Validation/Constraint/ValidReferenceConstraintValidator.php)

#0 /var/www/html/core/lib/Drupal/Core/TypedData/Validation/RecursiveContextualValidator.php(196): Drupal\Core\Entity\Plugin\Validation\Constraint\ValidReferenceConstraintValidator->validate()
#1 /var/www/html/core/lib/Drupal/Core/TypedData/Validation/RecursiveContextualValidator.php(148): Drupal\Core\TypedData\Validation\RecursiveContextualValidator->validateConstraints()
#2 /var/www/html/core/lib/Drupal/Core/TypedData/Validation/RecursiveContextualValidator.php(158): Drupal\Core\TypedData\Validation\RecursiveContextualValidator->validateNode()
#3 /var/www/html/core/lib/Drupal/Core/TypedData/Validation/RecursiveContextualValidator.php(100): Drupal\Core\TypedData\Validation\RecursiveContextualValidator->validateNode()
#4 /var/www/html/core/lib/Drupal/Core/TypedData/Validation/RecursiveValidator.php(90): Drupal\Core\TypedData\Validation\RecursiveContextualValidator->validate()
#5 /var/www/html/core/lib/Drupal/Core/TypedData/TypedData.php(132): Drupal\Core\TypedData\Validation\RecursiveValidator->validate()
#6 /var/www/html/core/lib/Drupal/Core/Entity/ContentEntityBase.php(489): Drupal\Core\TypedData\TypedData->validate()
#7 /var/www/html/core/lib/Drupal/Core/Entity/ContentEntityForm.php(188): Drupal\Core\Entity\ContentEntityBase->validate()
#8 [internal function]: Drupal\Core\Entity\ContentEntityForm->validateForm()
#9 /var/www/html/core/lib/Drupal/Core/Form/FormValidator.php(82): call_user_func_array()
#10 /var/www/html/core/lib/Drupal/Core/Form/FormValidator.php(273): Drupal\Core\Form\FormValidator->executeValidateHandlers()
#11 /var/www/html/core/lib/Drupal/Core/Form/FormValidator.php(118): Drupal\Core\Form\FormValidator->doValidateForm()
#12 /var/www/html/core/lib/Drupal/Core/Form/FormBuilder.php(589): Drupal\Core\Form\FormValidator->validateForm()
#13 /var/www/html/core/lib/Drupal/Core/Form/FormBuilder.php(321): Drupal\Core\Form\FormBuilder->processForm()
#14 /var/www/html/core/lib/Drupal/Core/Controller/FormController.php(73): Drupal\Core\Form\FormBuilder->buildForm()
#15 [internal function]: Drupal\Core\Controller\FormController->getContentResult()
#16 /var/www/html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()
#17 /var/www/html/core/lib/Drupal/Core/Render/Renderer.php(573): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#18 /var/www/html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext()
#19 /var/www/html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext()
#20 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(158): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#21 /var/www/html/vendor/symfony/http-kernel/HttpKernel.php(80): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
#22 /var/www/html/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle()
#23 /var/www/html/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle()
#24 /var/www/html/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
#25 /var/www/html/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass()
#26 /var/www/html/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle()
#27 /var/www/html/modules/contrib/devel/webprofiler/src/StackMiddleware/WebprofilerMiddleware.php(38): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#28 /var/www/html/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\webprofiler\StackMiddleware\WebprofilerMiddleware->handle()
#29 /var/www/html/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#30 /var/www/html/core/lib/Drupal/Core/DrupalKernel.php(705): Stack\StackedHttpKernel->handle()
#31 /var/www/html/index.php(19): Drupal\Core\DrupalKernel->handle()
#32 {main}

💬 Support request
Status

Closed: outdated

Version

9.4

Component
Field 

Last updated about 7 hours ago

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇫🇷France dxx Bordeaux/Paris/La Baule

    If your field is not a reference to another entity, check that your field ItemList class extends the FieldItemList and not the EntityReferenceFieldItemList.

    Also, in the same class, check your computeValue() method to ensure that the createItem() method is called with the right value (eg not an object).

  • 🇫🇷France iheb.attia

    Thanks @dxx Comment#7 worked for me

Production build 0.71.5 2024