Skip to content

Instantly share code, notes, and snippets.

@JeromeChevalier
Last active December 5, 2018 12:56
Show Gist options
  • Save JeromeChevalier/374aabf973d696c43faa1af5918ca41b to your computer and use it in GitHub Desktop.
Save JeromeChevalier/374aabf973d696c43faa1af5918ca41b to your computer and use it in GitHub Desktop.
Create a entity basefield with an entity reference type #drupal8
$fields['physical_location'] = BaseFieldDefinition::create('entity_reference')->setLabel(t('Physical Location'))
->setDescription(t('Reference the idenfication number of a physical location'))
->setRevisionable(FALSE)
->setSetting('target_type', 'site_entity')
->setSetting('handler', 'default')
->setTranslatable(FALSE)
->setDisplayOptions('form', [
'type' => 'entity_reference_autocomplete',
'settings' => [
'match_operator' => 'CONTAINS',
'size' => 50,
'placeholder' => t('Enter identification number of label'),
],
])
->setDisplayOptions('view', [
'label' => t("Physical Location"),
'type' => 'string',
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment