php 8.1 Deprecated function: Return type of Drupal ReturnTypeWillChange

Created on 24 May 2022, over 2 years ago
Updated 8 March 2023, almost 2 years ago

Problem/Motivation

Editing /admin/config/regional/name/list gives the following on D9.3.13 with php 8.1.2:

Deprecated function: Return type of Drupal\name\Render\NameListFormattableMarkup::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in include() (line 13 of modules/contrib/name/src/Render/NameListFormattableMarkup.php).

include('/var/www/html/modules/contrib/name/src/Render/NameListFormattableMarkup.php') (Line: 571)
Composer\Autoload\includeFile('/var/www/html/modules/contrib/name/src/Render/NameListFormattableMarkup.php') (Line: 428)
Composer\Autoload\ClassLoader->loadClass('Drupal\name\Render\NameListFormattableMarkup') (Line: 189)
Drupal\name\NameFormatter->formatList(Array, 'family', 'default') (Line: 149)
Drupal\name\NameListFormatListBuilder->examples(Object) (Line: 127)
Drupal\name\NameListFormatListBuilder->buildRow(Object) (Line: 219)
Drupal\Core\Entity\EntityListBuilder->render() (Line: 23)
Drupal\Core\Entity\Controller\EntityListController->listing('name_list_format')
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 564)
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: 158)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 80)
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: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 708)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)


Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡¦πŸ‡ΉAustria maxilein

Live updates comments and jobs are added and updated live.
  • PHP 8.1

    The issue particularly affects sites running on PHP version 8.1.0 or later.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

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

  • πŸ‡ΊπŸ‡ΈUnited States gbirch

    If you are getting the "Undefined array key "compare_format" in Drupal\name\Plugin\diff\Field\NameFieldBuilder->build()" warning, it appears that you can fix it by going to /admin/config/content/diff/fields and updating the configuration for any Name fields. Name does not provide a default diff format. Once you set one, the warning goes away.

  • πŸ‡¦πŸ‡ΉAustria maxilein

    @gbirch that sounds great. But a name field on a user object is not listed there.

    I also tried to resave all accounts - but it did not work

  • πŸ‡ΊπŸ‡ΈUnited States gbirch

    @maxilein The error from "NameFieldBuilder" is only going to come from a "name" field provided by the Name module (confusingly enough, the name of a user is not, in fact, a name field provided by the module). If you don't see a field listed on /admin/config/content/diff/fields that shows "Name" as its "Field Type," then are you sure you're really getting a NameFieldBuilder error? This is a field-level configuration problem, by the way - saving the user accounts (or any type of content) is never going to do anything for you. This is only solvable on the page mentioned.

  • πŸ‡¦πŸ‡ΉAustria maxilein

    Following your suggestion I went to the field specification on the user type and saved it.

    It only happens on update. Creating a new user does not cause problems.

    I have attached a screenshot of the config of the only name field in use on the entire site.

    
    Warning: Undefined array key "compare_format" in Drupal\name\Plugin\diff\Field\NameFieldBuilder->build() (line 73 of modules/contrib/name/src/Plugin/diff/Field/NameFieldBuilder.php).
    
        Drupal\name\Plugin\diff\Field\NameFieldBuilder->build(Object) (Line: 94)
        Drupal\diff\DiffEntityParser->parseEntity(Object) (Line: 104)
        Drupal\diff\DiffEntityComparison->compareRevisions(Object, Object) (Line: 181)
        Drupal\elogger\Services\Elogger->entityDiff(Object) (Line: 472)
        Drupal\elogger\Services\Elogger->prepareEntityLogMessage('entity_update', Object) (Line: 532)
        Drupal\elogger\Services\Elogger->logEvent('entity_update') (Line: 73)
        _log_entity_event('entity_update', Object) (Line: 50)
        elogger_entity_update(Object)
        call_user_func_array(Object, Array) (Line: 426)
        Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}(Object, 'elogger') (Line: 405)
        Drupal\Core\Extension\ModuleHandler->invokeAllWith('entity_update', Object) (Line: 433)
        Drupal\Core\Extension\ModuleHandler->invokeAll('entity_update', Array) (Line: 251)
        Drupal\Core\Entity\EntityStorageBase->invokeHook('update', Object) (Line: 900)
        Drupal\Core\Entity\ContentEntityStorageBase->invokeHook('update', Object) (Line: 598)
        Drupal\Core\Entity\EntityStorageBase->doPostSave(Object, 1) (Line: 781)
        Drupal\Core\Entity\ContentEntityStorageBase->doPostSave(Object, 1) (Line: 523)
        Drupal\Core\Entity\EntityStorageBase->save(Object) (Line: 804)
        Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object) (Line: 339)
        Drupal\Core\Entity\EntityBase->save() (Line: 46)
        Drupal\user\ProfileForm->save(Array, Object)
        call_user_func_array(Array, Array) (Line: 114)
        Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 52)
        Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 597)
        Drupal\Core\Form\FormBuilder->processForm('user_form', Array, Object) (Line: 325)
        Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
        Drupal\Core\Controller\FormController->getContentResult(Object, Object) (Line: 39)
        Drupal\layout_builder\Controller\LayoutBuilderHtmlEntityFormController->getContentResult(Object, Object)
        call_user_func_array(Array, Array) (Line: 123)
        Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580)
        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: 169)
        Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
        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: 48)
        Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
        Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
        Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 718)
        Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
    
        Warning: Undefined array key "compare_format" in Drupal\name\Plugin\diff\Field\NameFieldBuilder->build() (line 73 of modules/contrib/name/src/Plugin/diff/Field/NameFieldBuilder.php).
    
        Drupal\name\Plugin\diff\Field\NameFieldBuilder->build(Object) (Line: 94)
        Drupal\diff\DiffEntityParser->parseEntity(Object) (Line: 105)
        Drupal\diff\DiffEntityComparison->compareRevisions(Object, Object) (Line: 181)
        Drupal\elogger\Services\Elogger->entityDiff(Object) (Line: 472)
        Drupal\elogger\Services\Elogger->prepareEntityLogMessage('entity_update', Object) (Line: 532)
        Drupal\elogger\Services\Elogger->logEvent('entity_update') (Line: 73)
        _log_entity_event('entity_update', Object) (Line: 50)
        elogger_entity_update(Object)
        call_user_func_array(Object, Array) (Line: 426)
        Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}(Object, 'elogger') (Line: 405)
        Drupal\Core\Extension\ModuleHandler->invokeAllWith('entity_update', Object) (Line: 433)
        Drupal\Core\Extension\ModuleHandler->invokeAll('entity_update', Array) (Line: 251)
        Drupal\Core\Entity\EntityStorageBase->invokeHook('update', Object) (Line: 900)
        Drupal\Core\Entity\ContentEntityStorageBase->invokeHook('update', Object) (Line: 598)
        Drupal\Core\Entity\EntityStorageBase->doPostSave(Object, 1) (Line: 781)
        Drupal\Core\Entity\ContentEntityStorageBase->doPostSave(Object, 1) (Line: 523)
        Drupal\Core\Entity\EntityStorageBase->save(Object) (Line: 804)
        Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object) (Line: 339)
        Drupal\Core\Entity\EntityBase->save() (Line: 46)
        Drupal\user\ProfileForm->save(Array, Object)
        call_user_func_array(Array, Array) (Line: 114)
        Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 52)
        Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 597)
        Drupal\Core\Form\FormBuilder->processForm('user_form', Array, Object) (Line: 325)
        Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
        Drupal\Core\Controller\FormController->getContentResult(Object, Object) (Line: 39)
        Drupal\layout_builder\Controller\LayoutBuilderHtmlEntityFormController->getContentResult(Object, Object)
        call_user_func_array(Array, Array) (Line: 123)
        Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580)
        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: 169)
        Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
        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: 48)
        Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
        Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
        Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 718)
        Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
    
    
    
    
  • πŸ‡ΊπŸ‡ΈUnited States gbirch

    @maxilein, this configuration has to be done in the settings for the diff module at https://YOUR_SITE/admin/config/content/diff/fields If you do not start at that URL, you are starting in the wrong place. See the attached image of the top of that page.

    The picture you have attached is for the field settings form, which, again, is not the right place. You need DIFF settings.

    Hope that helps.

  • πŸ‡¦πŸ‡ΉAustria maxilein

    Thank you very much.

    /admin/config/content/diff/fields has no USER entity.
    The name field is a custom field on the user entity.

  • πŸ‡ΊπŸ‡ΈUnited States gbirch

    @maxilein: Wow, I see the problem - while Name fields on content bundles are listed, Name fields on user entities are not. Sorry, I'm out of ideas here.

  • πŸ‡¦πŸ‡ΉAustria maxilein

    Thank you. We should move this issue to diff module then I think.

Production build 0.71.5 2024