0

My Code looks like this:

$fields['color'] = BaseFieldDefinition::create('entity_reference')
  ->setLabel(t('Color'))
  ->setDescription(t('The color of the fruit.'))
  ->setSetting('target_type', 'taxonomy_term')
  ->setSetting('handler', 'default:taxonomy_term')
  ->setSetting('handler_settings', ['target_bundles' => ['Color' => 'Color']])
  ->setDisplayOptions('view', [
    'label' => 'above',
    'type' => 'author',
    'weight' => -3,
  ])
  ->setDisplayOptions('form', [
    'type' => 'entity_reference_autocomplete',
    'settings' => [
      'match_operator' => 'CONTAINS',
      'size' => 60,
      'autocomplete_type' => 'tags',
      'placeholder' => '',
    ],
    'weight' => -3,
  ])
  ->setDisplayConfigurable('form', TRUE)
  ->setDisplayConfigurable('view', TRUE);

I have a vocabulary with the name : 'Color'
I have 3 terms in it : 'Red', 'Yellow', 'Green'

The error I'm getting is this :

enter image description here

I'm trying to figure out what went wrong.

  • Just Change the Color to color in ['target_bundles' => ['Color' => 'Color']]) if you create a vocabulary caller Color the machine name will be color Not Color . – berramou Sep 6 '19 at 16:15
0

Change the Color to color in ['target_bundles' => ['Color' => 'Color']]) if you create a vocabulary caller Color the machine name will be color Not Color So try with:

$fields['color'] = BaseFieldDefinition::create('entity_reference')
      ->setLabel(t('Color'))
      ->setDescription(t('The color of the fruit.'))
      ->setSetting('target_type', 'taxonomy_term')
      ->setSetting('handler', 'default:taxonomy_term')
      // Target is color not Color.
      ->setSetting('handler_settings', ['target_bundles' => ['color' => 'Color']])
      ->setDisplayOptions('view', [
        'label'  => 'above',
        'type'   => 'author',
        'weight' => -3,
      ])
      ->setDisplayOptions('form', [
        'type'     => 'entity_reference_autocomplete',
        'settings' => [
          'match_operator'    => 'CONTAINS',
          'size'              => 60,
          'autocomplete_type' => 'tags',
          'placeholder'       => '',
        ],
        'weight'   => -3,
      ])
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayConfigurable('view', TRUE);
| improve this answer | |
  • Thanks for the reply. My machine name is: fruits_color. So should I change it to ['fruits_color' => 'Color'] ? – Aman Devrath Sep 9 '19 at 5:42
  • welcome, yes you should change it to ['fruits_color' => 'Color'] – berramou Sep 9 '19 at 8:47
  • Now, getting a different error, 'taste' column unknown. not found in field list. sorry but cant understand this error – Aman Devrath Sep 9 '19 at 9:41
  • so you should debug this error not from this code there is no taste field as i can see – berramou Sep 9 '19 at 9:45
  • Okay, Thankyou sir. – Aman Devrath Sep 9 '19 at 10:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.