Autocomplete field widget error in case of BaseField

Created on 5 February 2021, almost 4 years ago
Updated 26 April 2024, 7 months ago

Problem/Motivation

I've created a BaseField definition for my custom entity and set the Country Autocomplete widget for this field. But faced an error:
Error: Call to undefined method Drupal\Core\Field\BaseFieldDefinition::get() in Drupal\country\Plugin\Field\FieldWidget\CountryAutocompleteWidget->formElement() (line 44 of modules/contrib/country/src/Plugin/Field/FieldWidget/CountryAutocompleteWidget.php).

Steps to reproduce

Below is the code for the field:

$fields['residence_country'] = BaseFieldDefinition::create('country')
      ->setLabel(t('Country of residence'))
      ->setRevisionable(TRUE)
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayConfigurable('view', TRUE)
      ->setRequired(TRUE);
πŸ› Bug report
Status

Closed: works as designed

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡¦Ukraine nikita_tt

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

Comments & Activities

Not all content is available!

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

  • πŸ‡³πŸ‡±Netherlands batigolix Utrecht

    I know it has been a long time since you posted this issue, but could you provide steps how to reproduce the error?

  • πŸ‡ΊπŸ‡¦Ukraine nikita_tt

    Hi. As I remember there was a problem if the field was a base field (defined in the entity class) of the custom entity type.

    Steps to reproduce:
    1. Create a custom entity type. It can be generated via drush or drupal console.
    2. Add the country field to this custom entity type. (baseFieldDefinitions method)

    $fields['residence_country'] = BaseFieldDefinition::create('country')
          ->setLabel(t('Country of residence'))
          ->setRevisionable(TRUE)
          ->setDisplayConfigurable('form', TRUE)
          ->setDisplayConfigurable('view', TRUE)
          ->setRequired(TRUE);
    

    3. Go to the entity create/edit form and try to add a value to the Country field. You will see the error.

    Note: I'm not sure whether the issue is still relevant or not.

  • πŸ‡³πŸ‡±Netherlands batigolix Utrecht
  • Status changed to Needs work 7 months ago
  • πŸ‡³πŸ‡±Netherlands batigolix Utrecht
  • Status changed to Closed: works as designed 7 months ago
  • πŸ‡³πŸ‡±Netherlands batigolix Utrecht

    I tested this with a custom entity and Country as a base field.

    The problem does not occur anymore.

Production build 0.71.5 2024