Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
This error is issued beginning with 8.x-2.16 Lightening update.
Notice: Undefined index: #prefix in Drupal\lightning_media\Plugin\Field\FieldWidget\EntityReferenceBrowserWidget->formElement()
Complete error:
Notice: Undefined index: #prefix in Drupal\lightning_media\Plugin\Field\FieldWidget\EntityReferenceBrowserWidget->formElement() (line 21 of profiles/contrib/lightning/modules/lightning_features/lightning_media/src/Plugin/Field/FieldWidget/EntityReferenceBrowserWidget.php).
Drupal\lightning_media\Plugin\Field\FieldWidget\EntityReferenceBrowserWidget->formElement(Object, 0, Array, Array, Object) (Line: 322)
Drupal\Core\Field\WidgetBase->formSingleElement(Object, 0, Array, Array, Object) (Line: 85)
Drupal\Core\Field\WidgetBase->form(Object, Array, Object) (Line: 298)
Drupal\Core\Field\FieldItemList->defaultValuesForm(Array, Object) (Line: 97)
Drupal\field_ui\Form\FieldConfigEditForm->form(Array, Object) (Line: 115)
Drupal\Core\Entity\EntityForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 514)
Drupal\Core\Form\FormBuilder->retrieveForm('field_config_edit_form', Object) (Line: 271)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 74)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 574)
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}()
call_user_func_array(Object, Array) (Line: 144)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 64)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 656)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
Comments
Comment #2
sdmeyers CreditAttribution: sdmeyers as a volunteer commentedThis seems to fix the error...
Comment #3
balsamaHi. I'm not seeing this error out-of-the-box or in our test environment. Do you have any other details or steps to reproduce to share? That Field Widget was added a couple of months ago as an enhancement to media reference fields.
Comment #4
balsamaSorry, looks like our comments overlapped.
So this is the same issue reported over here: https://github.com/acquia/lightning/pull/375
I'd like to get to the bottom of why that element is undefined before working around it. Per this comment, I don't see any way that the $element passed to that function could be lacking
['current']['#prefix']
.Can you confirm that you have patch 10 from 2877751 applied to Entity Browser?
Comment #5
sdmeyers CreditAttribution: sdmeyers as a volunteer commentedThis occurs when I add a "Teaser Image" field to a node content type.
Steps to reproduce:
1. Select a content type (i.e. "Basic Page")
2. + Add Field -> Add a new field -> Reference-Media
3. Label - (i.e.) "Teaser Image"
4. Save and Continue
5. Type of item to reference: Media
6. Allowed number of values: Limited 1
7. Save field settings
...BAM! error first appears here and will reappear anytime you try to create/edit a node of this content type...
8. Finish up adding field.
Comment #6
sdmeyers CreditAttribution: sdmeyers as a volunteer commentedIt does not appear the patch you mention is applied to Entity Browser. Is there some documentation somewhere that indicated this is needed? (should this have happened when updating lightening via composer?)
Comment #7
balsamaYeah, that patch is definitely needed. Lightning will automatically apply it for you if everything is set up correctly.
What are you using for a scaffold project (lightning-project? BLT?) Can you paste your root composer.json file?
Comment #8
sdmeyers CreditAttribution: sdmeyers as a volunteer commentedcomposer,json ->
Comment #9
balsamaI was looking for
"enable-patching": true
in"extra"
, which you have. I don't see any reason you shouldn't be getting that patch. But your steps to reproduce indicate that it's not there.I guess you could try blowing away your modules directory and your lock file and running composer update.
Comment #10
sdmeyers CreditAttribution: sdmeyers as a volunteer commentedIt seems somehow the patch initially failed.
I think it may have been the old version of cweagans.
Changed
"cweagans/composer-patches": "1.5.0",
to"cweagans/composer-patches": "^1.6.0",
Then emptied the the
vendor
directory and updated. This caused most everything to be re-downloaded, patched and installed.It seems more then just that one patch was missing.
Error has gone away. It was just the mossed patch. Thanks for the help in troubleshooting this!
Comment #11
balsamaAwesome!