My goal was to create a taxonomy reference field in Drupal 8.2.
Consider these to field definitions on an entity.
// #1
$fields[$field] = BaseFieldDefinition::create('entity_reference')
->setTargetEntityTypeId('taxonomy_term')
// #2
$fields[$field] = BaseFieldDefinition::create('entity_reference')
->setSetting('target_type', 'taxonomy_term')
Here is how #1 is documented:
/**
* Sets the ID of the type of the entity this field is attached to.
*
* @param string $entity_type_id
* The name of the target entity type to set.
*
* @return $this
*/
public function setTargetEntityTypeId($entity_type_id) {
Looking at the description both should produce the same result - set target entity type.
The #1 creates me an input with autocomplete from page names and page types.
The #2 creates n input with autocomplete from taxonomy terms.
Why does this happen and what is #1 is meant to do?