0

I created a custom module which has an custom entity. I added base field term_id to it using below code

$fields['term_id'] = BaseFieldDefinition::create('entity_reference')
    ->setLabel(t('Category'))
    ->setDescription(t('Default Category.'))
    ->setRevisionable(TRUE)
    ->setSetting('target_type', 'taxonomy_term')
    ->setSetting('handler', 'default:taxonomy_term')
    ->setSetting('handler_settings', [
            'target_bundles' => ['question_category' => 'question_category']
        ]
    )
    ->setTranslatable(TRUE)
    ->setDisplayOptions('view', array(
        'label' => 'hidden',
        'type' => 'author',
        '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 have a YAML file taxonomy.vocabulary.question_category.yml, which create question_category vocabulary, I can see it in admin too.

But when I try to add a new text in it. I get an error There are no entities matching ||new enitity title||

I want user to create terms and add it to question_category taxonomy.

Please suggest, what might be the error.

--

Thanks

1

I did it using below handler setting

setSetting('handler_settings', ['target_bundles' => ['question_sub_category' => 'question_sub_category'], 'auto_create' => TRUE])

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.