I have an Entity:
EntityX. It installs correctly and works the way that I want it to; with, of course, one exception.
I want to attach an entity reference to a specific vocabulary. I have tried:
My vocabulary's machine name is:
EntityX's definition I have the following defined in the
$fields['my_custom_vocabulary'] = BaseFieldDefinition::create('entity_reference') ->setLabel(t('Vocabulary')) ->setDescription(t('What was this tagged with.')) ->setSetting('target_type', 'custom_vocabulary') ->setSetting('handler', 'default') ->setDisplayOptions('view', array( 'label' => 'above', 'type' => 'author', 'weight' => -3, )) ->setDisplayOptions('form', array( 'type' => 'entity_reference_autocomplete', 'settings' => array( 'match_operator' => 'CONTAINS', 'size' => 60, 'placeholder' => '', ), 'weight' => -3, )) ->setDisplayConfigurable('form', TRUE) ->setDisplayConfigurable('view', TRUE);
But when I go to install it, I get the following error:
Drupal\Component\Plugin\Exception\PluginNotFoundException: The "custom_vocabulary" entity type does not exist. in /brew/www/html/core/lib/Drupal/Core/Entity/EntityTypeManager.php:133
While looking at the article defined in the
installation profile for Drupal, I see that they use it as a field and not a true entity reference. Is there no way for me to do it this way? I can't have this all nicely bundled into one single entity.
What I don't know how to do is add a term from a vocabulary to an entity type.