Problem/Motivation

Error: Call to undefined method Drupal\Core\Field\BaseFieldDefinition::get() in Drupal\entity_browser\Plugin\Field\FieldWidget\EntityReferenceBrowserWidget->settingsForm()

That's because it is using get('uuid') to get a unique value for the HTML ID, but that only exists when it is a config entity.

It should use getUniqueIdentifier() instead, which exists exactly for this reason.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Original summary

Hi, I am using entity browser in drupal commerce 2 project, and when trying to add entitybrowser to pick a commerce_product_variation as widget throbber never ends.
It raises this error in error log:

 2019/07/17 18:21:36 [error] 7905#7905: *112739 FastCGI sent in stderr: "PHP message: Error: Call to undefined method Drupal\Core\Field\BaseFieldDefinition::get() in /drupal-project/web/modules/contrib/entity_browser/src/Plugin/Field/FieldWidget/EntityReferenceBrowserWidget.php on line 176 
#0 drupal-project/web/core/modules/field_ui/src/Form/EntityDisplayFormBase.php(455): Drupal\entity_browser\Plugin\Field\FieldWidget\EntityReferenceBrowserWidget->settingsForm(Array, Object(Drupal\Core\Form\FormState))
#1 drupal-project/web/core/modules/field_ui/src/Form/EntityFormDisplayEditForm.php(40): Drupal\field_ui\Form\EntityDisplayFormBase->buildFieldRow(Object(Drupal\Core\Field\BaseFieldDefinition), Array, Object(Drupal\Core\Form\FormState))
#2 drupal-project/web/core/modules/field_ui/src/Form/EntityDisplayFormBase.php(218): Drupal\field_ui\Form\EntityFormDisplayEditForm->buildFieldRow(Object(Drupal\Core\Field\BaseFieldDefinition), Array, Object(Drupal\Core\Form\" while reading response header from upstream, client: ******** , server: *************** , request: "POST /admin/commerce/config/order-item-types/default_order/edit/form-display?ajax_form=1&_wrapper_format=drupal_ajax HTTP/1.1", upstream: "f******", host: "************", referrer: "http://***********/admin/commerce/config/order-item-types/default_order/edit/form-display"

It works with 2.1 version

Comments

aleix created an issue. See original summary.

erik seifert’s picture

StatusFileSize
new860 bytes

`BaseFieldDefinition::get` is not defined. Should use `FieldDefinitionInterface::getUniqueIdentifier'

oknate’s picture

Status: Active » Needs review

oknate credited Berdir.

oknate’s picture

Title: Cannot add widget in any form » Fatal error when using the entity browser widget on a base field
Issue summary: View changes

Updating summary, and crediting Berdir, who created a better issue name and summary in a duplicate: #3071075: Fatal error when using the entity browser widget on a base field.

oknate’s picture

Status: Needs review » Reviewed & tested by the community

  • oknate committed c58784b on 8.x-2.x authored by Erik Seifert
    Issue #3068557 by Erik Seifert, Berdir: Fatal error when using the...

  • oknate committed 115069a on 8.x-1.x authored by Erik Seifert
    Issue #3068557 by Erik Seifert, Berdir: Fatal error when using the...
oknate’s picture

Status: Reviewed & tested by the community » Fixed
StatusFileSize
new179.49 KB

Here's a screenshot showing the bug on the "Authored By" field on the node entity:

authored by

It's pretty easy to confirm the fix using that field.

Here's a follow-up to add test coverage: #3071110: Add test coverage for BaseFieldDefinition fix.

Status: Fixed » Closed (fixed)

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

akerbel.dev’s picture

I have updated the patch for 2.2.0 version.

akerbel.dev’s picture

akerbel.dev’s picture

Sorry, I have used a wrong branch.

mykola dolynskyi’s picture

Also having fatal error when changing order (in edit form) of fields defined in module of custom entity

Call to undefined method Drupal\Core\Field\BaseFieldDefinition::get() in Drupal\entity_browser\Plugin\Field\FieldWidget\EntityReferenceBrowserWidget->settingsForm()

oknate’s picture

This should be fixed (again) on the dev branch, see #3000587: the md5() and sha1() hash functions should never be used in any code.

There was a regression, due to that issue that broke this one.