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

sdmeyers created an issue. See original summary.

sdmeyers’s picture

This seems to fix the error...

--- EntityReferenceBrowserWidget.php	2017-07-05 15:11:52.000000000 -0400
+++ EntityReferenceBrowserWidget.patch.php	2017-07-06 09:55:14.000000000 -0400
@@ -18,8 +18,10 @@
     $element = parent::formElement($items, $delta, $element, $form, $form_state);
 
     // Move the remaining number of selections to the details summary.
-    $element['#description'] .= $element['current']['#prefix'];
-    unset($element['current']['#prefix']);
+    if(isset($element['current']['#prefix'])) {
+      $element['#description'] .= $element['current']['#prefix'];
+      unset($element['current']['#prefix']);
+    }
 
     // Wrap the current selections in a nice <details> element.
     $cardinality = $this->fieldDefinition
balsama’s picture

Hi. 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.

balsama’s picture

Sorry, 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?

sdmeyers’s picture

This 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.

sdmeyers’s picture

It 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?)

balsama’s picture

Yeah, 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?

sdmeyers’s picture

composer,json ->

{
    "name": "acquia/lightning-project",
    "description": "Project template for Drupal 8 sites built with the Lightning distribution.",
    "type": "project",
    "license": "GPL-2.0+",
    "minimum-stability": "dev",
    "prefer-stable": true,
    "require-dev": {
        "drupal/drupal-extension": "^3.2",
        "behat/mink": "~1.7",
        "behat/mink-goutte-driver": "~1.2",
        "jcalderonzumba/gastonjs": "~1.0.2",
        "drupal/coder": "8.*",
        "mikey179/vfsStream": "~1.2",
        "phpunit/phpunit": "~4.8",
        "symfony/css-selector": "~2.8",
        "behat/behat": "^3.0",
        "se/selenium-server-standalone": "^2.53",
        "composer/composer": "^1.3"
    },
    "require": {
        "composer/installers": "^1.0",
        "drupal-composer/drupal-scaffold": "^2.0.0",
        "cweagans/composer-patches": "1.5.0",
        "acquia/lightning": "^2.0.0",
        "drupal/devel": "^1.0@RC",
        "drupal/admin_toolbar": "^1.18",
        "drupal/linkit": "^5.0",
        "drupal/field_group": "^1.0@RC",
        "drupal/paragraphs": "^1.1",
        "drupal/entity_reference_revisions": "^1.2"
    },
    "repositories": {
        "packages.drupal.org": {
            "type": "composer",
            "url": "https://packages.drupal.org/8"
        }
    },
    "scripts": {
        "post-install-cmd": [
            "DrupalComposer\\DrupalScaffold\\Plugin::scaffold",
            "Acquia\\Lightning\\ScriptHandler::deployLibraries"
        ],
        "post-update-cmd": [
            "DrupalComposer\\DrupalScaffold\\Plugin::scaffold",
            "Acquia\\Lightning\\ScriptHandler::deployLibraries"
        ]
    },
    "config": {
        "bin-dir": "bin/"
    },
    "autoload": {
        "classmap": [
            "scripts/ScriptHandler.php"
        ]
    },
    "extra": {
        "installer-paths": {
            "docroot/core": [
                "drupal/core"
            ],
            "docroot/modules/contrib/{$name}": [
                "type:drupal-module"
            ],
            "docroot/profiles/contrib/{$name}": [
                "type:drupal-profile"
            ],
            "docroot/themes/contrib/{$name}": [
                "type:drupal-theme"
            ],
            "drush/contrib/{$name}": [
                "type:drupal-drush"
            ]
        },
        "enable-patching": true
    }
}
balsama’s picture

Issue tags: +composer support request

I 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.

sdmeyers’s picture

It 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!

balsama’s picture

Status: Active » Closed (outdated)

Awesome!