I'm on Drupal 8, using BaseFieldDefinition::create('entity_reference')
on my custom entity type to add entity reference field;
I also use this ->setSetting('target_type', 'node')
to get nodes but this gives me all nodes of any content type;
Is there any way or possibility to filter these nodes to specific content type?
Here is the code for my field:
$fields['project_id'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Project'))
->setDescription(t('The project ID, transaction was created for.'))
->setSetting('target_type', 'node')
->setSetting('handler', 'default')
->setTargetEntityTypeId('project')
->setDisplayOptions('view', array(
'label' => 'hidden',
'type' => 'project',
'weight' => 0,
))
->setDisplayOptions('form', array(
'type' => 'entity_reference_autocomplete',
'weight' => 5,
'settings' => array(
'match_operator' => 'CONTAINS',
'size' => '60',
'autocomplete_type' => 'tags',
'placeholder' => '',
),
))
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
I want this field to be referenced to Content Type called project
and not all types of nodes.