I have a few custom vocabulary defiend which have nothing to do with each other (f.e. colors and music). I like to define a field that allows only taxonomy-terms from one vocabulary. I have found lots of equal examples that using all vocabulary, but I didn't found anything for using only a part of the vocabularys.

This is what I found:

$fields['refTaxId'] = BaseFieldDefinition::create('entity_reference')
      ->setLabel(t('custom taxonomy'))
      ->setDescription(t('Get a value from a custom taxonomy'))
      ->setSetting('target_type', 'taxonomy_term');

I think i need to something like this:

->setSetting('?????', 'colors')

Any ideas, hints?

thx CW

Comments

CooleWampe’s picture

After a extensive search (over one week), I've found something like this...

    $fields['color_id'] = BaseFieldDefinition::create('entity_reference')
      ->setLabel(t('color'))
      ->setDescription(t('select colors'))
      ->setSetting('target_type', 'taxonomy_term')	
      ->setSetting('handler_settings', ['target_bundles' => ['taxonomy_term' => 'vocabuluary_machine_name_color']])
		->setDisplayOptions('view', array(
						      'label' => 'above',
						      'type' => 'taxonomy_term',
						))
     ->setDisplayOptions('form', array(
						'type' => 'taxonomy_term',
						'settings' => array(
										'match_operator' => 'CONTAINS',
										'autocomplete_type' => 'tags',
									),
				))
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayConfigurable('view', TRUE);

Thx CW