Problem/Motivation
The module throws this error on a site.
Deprecated function: Creation of dynamic property Drupal\do_username\DOComputedFields::$doUserService is deprecated in Drupal\do_username\DOComputedFields->__construct() (line 22 of modules/contrib/do_username/src/DOComputedFields.php).
Drupal\do_username\DOComputedFields->__construct(Object, 'bio', Object) (Line: 47)
Drupal\Core\TypedData\TypedData::createInstance(Object, 'bio', Object) (Line: 91)
Drupal\Core\TypedData\TypedDataManager->createInstance('string', Array) (Line: 100)
Drupal\Core\TypedData\TypedDataManager->create(Object, NULL, 'bio', Object) (Line: 200)
Drupal\Core\TypedData\TypedDataManager->getPropertyInstance(Object, 'bio') (Line: 66)
Drupal\Core\Field\FieldItemBase->__construct(Object, 'bio', Object) (Line: 47)
Drupal\Core\TypedData\TypedData::createInstance(Object, 0, Object) (Line: 91)
Drupal\Core\TypedData\TypedDataManager->createInstance('field_item:do_username', Array) (Line: 100)
Drupal\Core\TypedData\TypedDataManager->create(Object, NULL, 0, Object) (Line: 200)
Drupal\Core\TypedData\TypedDataManager->getPropertyInstance(Object, 0, Array) (Line: 82)
Drupal\Core\Field\FieldTypePluginManager->createFieldItem(Object, 0, Array) (Line: 41)
Drupal\Core\Field\FieldItemList->createItem(0, Array) (Line: 69)
Drupal\Core\TypedData\Plugin\DataType\ItemList->setValue(Array, ) (Line: 107)
Drupal\Core\Field\FieldItemList->setValue(Array, ) (Line: 208)
Drupal\Core\TypedData\TypedDataManager->getPropertyInstance(Object, 'field_do_username', Array) (Line: 74)
Drupal\Core\Field\FieldTypePluginManager->createFieldItemList(Object, 'field_do_username', Array) (Line: 600)
Drupal\Core\Entity\ContentEntityBase->getTranslatedField('field_do_username', 'x-default') (Line: 564)
Drupal\Core\Entity\ContentEntityBase->get('field_do_username') (Line: 181)
Drupal\Core\Entity\Entity\EntityFormDisplay->buildForm(Object, Array, Object) (Line: 121)
Drupal\Core\Entity\ContentEntityForm->form(Array, Object) (Line: 311)
Drupal\user\AccountForm->form(Array, Object) (Line: 107)
Drupal\Core\Entity\EntityForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 536)
Drupal\Core\Form\FormBuilder->retrieveForm('user_form', Object) (Line: 283)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 592)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 121)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 182)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 53)
Asm89\Stack\Cors->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)Steps to reproduce
Just install the module and view a form where this field is present. This might also show up on other pages randomly (errors shown from session).
Proposed resolution
It's an easy enough fix. Define the property in the class as indicated by the error message.
Issue fork do_username-3394977
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3394977-1
compare
- 3394977-deprecation-error-in
changes, plain diff MR !6
Comments
Comment #2
hussainwebComment #3
abhishek_gupta1 commentedComment #5
abhishek_gupta1 commented@hussainweb, I have fix the issue Deprecation error in DOComputedFields. please kindly review the MR
Comment #6
hussainweb@abhishek_virasat, I think you're trying to rely on autowiring for this to work, but autowiring is not enabled. Did you maybe forget to commit that change? Or am I missing something here?
Comment #7
hussainwebIMHO, we can just fix the error here. Autowiring and testing it is a larger problem we can worry about later. I am not sure that TypedData even supports injection this way. Of course, I wrote this ages ago when autowiring was not implemented in Drupal core, so things must have changed.
The fix is already there in your MR. You just need to remove the injection bits and we can create another issue to inject the service properly.
Comment #8
hussainwebComment #10
hussainwebThanks for your work but I want to make a release today and so I am just going to push a simple fix for now. We can consider autowiring later. If you're interested in taking this further, please create an issue.