Unable to add an extra field on a content type/bundle that has no extra fields already

Created on 11 April 2024, 8 months ago
Updated 27 August 2024, 4 months ago

Problem/Motivation

I've just updated to v2.1.0-rc1, on a site running Drupal 9.5.11 using PHP 8.1.27. When trying to add an extra field on a content type (bundle) that doesn't already have any extra fields, using /admin/structure/types/manage/article/extra-fields/add, the page doesn't load. This works fine using v2.0.0-alpha5. The following is logged:

Error: Typed property Drupal\entity_extra_field\Entity\EntityExtraField::$name must not be accessed before initialization in Drupal\entity_extra_field\Entity\EntityExtraField->name() (line 149 of /public_html/modules/contrib/entity_extra_field/src/Entity/EntityExtraField.php)
#0 /public_html/modules/contrib/entity_extra_field/src/Form/EntityExtraFieldForm.php(148): Drupal\entity_extra_field\Entity\EntityExtraField->name()
#1 /public_html/core/lib/Drupal/Core/Entity/EntityForm.php(106): Drupal\entity_extra_field\Form\EntityExtraFieldForm->form(Array, Object(Drupal\Core\Form\FormState))
#2 [internal function]: Drupal\Core\Entity\EntityForm->buildForm(Array, Object(Drupal\Core\Form\FormState))
#3 /public_html/core/lib/Drupal/Core/Form/FormBuilder.php(536): call_user_func_array(Array, Array)
#4 /public_html/core/lib/Drupal/Core/Form/FormBuilder.php(283): Drupal\Core\Form\FormBuilder->retrieveForm('entity_extra_fi...', Object(Drupal\Core\Form\FormState))
#5 /public_html/core/lib/Drupal/Core/Controller/FormController.php(73): Drupal\Core\Form\FormBuilder->buildForm(Object(Drupal\entity_extra_field\Form\EntityExtraFieldForm), Object(Drupal\Core\Form\FormState))
#6 [internal function]: Drupal\Core\Controller\FormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch))
#7 /public_html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#8 /public_html/core/lib/Drupal/Core/Render/Renderer.php(580): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#9 /public_html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#10 /public_html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
#11 /vendor/symfony/http-kernel/HttpKernel.php(169): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#12 /vendor/symfony/http-kernel/HttpKernel.php(81): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#13 /public_html/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#14 /public_html/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#15 /public_html/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#16 /public_html/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#17 /public_html/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#18 /public_html/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#19 //vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#20 /public_html/core/lib/Drupal/Core/DrupalKernel.php(718): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#21 /public_html/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#22 {main}
πŸ› Bug report
Status

Fixed

Version

2.1

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom natts London

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

Comments & Activities

  • Issue created by @natts
  • Here i m uploading patch to resolve the above issue. Please review it

  • @praveen-rani opened merge request.
  • πŸ‡¬πŸ‡§United Kingdom jaydenpearly

    The patch has been tested. The patch could not be applied.

    Checking patch src/Entity/EntityExtraField.php...
    error: while searching for:
      /**
       * @var string
       */
      public $name;
    
      /**
       * @var string
    
    error: patch failed: src/Entity/EntityExtraField.php:67
    error: src/Entity/EntityExtraField.php: patch does not apply
    
  • πŸ‡¬πŸ‡§United Kingdom natts London
  • Re-made the patch from #2

  • Status changed to Needs review 8 months ago
  • πŸ‡³πŸ‡ΏNew Zealand ericgsmith
  • Status changed to RTBC 8 months ago
  • πŸ‡³πŸ‡ΏNew Zealand ericgsmith

    Tested patch #9 and it resolves this error.

    Did not test MR but looks exactly the same - needs to be updated to target 2.1.x branch?

  • πŸ‡¨πŸ‡¦Canada slideaway

    Can confirm #6 patch fixes this issue for me.

    • droath β†’ committed 45ee5bda on 2.1.x
      Issue #3440363 by praveen rani, Ruichao, ericgsmith: Unable to add an...
  • πŸ‡§πŸ‡ͺBelgium Vacilando Brussels

    +1, please commit to dev at least.

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

    @Vacilando

    Could you please provide more details on when you encounter that error? I am unable to replicate it. The patch that has been merged appears to be functioning correctly for me on a fresh Drupal installation.

  • πŸ‡§πŸ‡ͺBelgium Vacilando Brussels
    The website encountered an unexpected error. Try again later.
    
    Error: Call to a member function getName() on null in Drupal\Core\Config\Entity\ConfigEntityStorage->doLoadMultiple() (line 206 of core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php).
    Drupal\Core\Entity\EntityStorageBase->loadMultiple() (Line: 26)
    entity_extra_field_entity_extra_field_info()
    call_user_func_array(Object, Array) (Line: 416)
    Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}(Object, 'entity_extra_field') (Line: 395)
    Drupal\Core\Extension\ModuleHandler->invokeAllWith('entity_extra_field_info', Object) (Line: 423)
    Drupal\Core\Extension\ModuleHandler->invokeAll('entity_extra_field_info') (Line: 676)
    Drupal\Core\Entity\EntityFieldManager->loadExtraFields() (Line: 649)
    Drupal\Core\Entity\EntityFieldManager->getExtraFields('node', 'problem') (Line: 173)
    Drupal\Core\Entity\EntityDisplayBase->init() (Line: 155)
    Drupal\Core\Entity\EntityDisplayBase->__construct(Array, 'entity_view_display') (Line: 181)
    Drupal\Core\Entity\Entity\EntityViewDisplay->__construct(Array, 'entity_view_display') (Line: 418)
    Drupal\Core\Entity\EntityStorageBase->mapFromStorageRecords(Array) (Line: 186)
    Drupal\Core\Config\Entity\ConfigEntityStorage->doLoadMultiple(Array) (Line: 312)
    Drupal\Core\Entity\EntityStorageBase->loadMultiple(Array) (Line: 121)
    Drupal\Core\Entity\Entity\EntityViewDisplay::collectRenderDisplays(Array, 'full') (Line: 281)
    Drupal\Core\Entity\EntityViewBuilder->buildMultiple(Array) (Line: 239)
    Drupal\Core\Entity\EntityViewBuilder->build(Array)
    call_user_func_array(Array, Array) (Line: 113)
    Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/2966725', 'exception', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 870)
    Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 432)
    Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 248)
    Drupal\Core\Render\Renderer->render(Array, ) (Line: 238)
    Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 638)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 239)
    Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 128)
    Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
    Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
    call_user_func(Array, Object, 'kernel.view', Object) (Line: 111)
    Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 186)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 53)
    Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
    Drupal\Core\StackMiddleware\ContentLength->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: 36)
    Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 741)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
  • Status changed to Fixed 4 months ago
  • πŸ‡©πŸ‡ͺGermany Grevil

    What were the exact steps you took @Vacilando?

    Did you update the module from "2.0.0-alpha5" to "2.1.x dev"? What extra field type were you using on the node? Are you using the extra field on the form or view display?

    Please provide further information, so we can try to reproduce this issue! πŸ™‚

    Setting to "Fixed" for now, as the original issue was already merged.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024