I am trying to add a new text field to the menu in Drupal 8, and I have done it using the instruction in the following post:
Add field(s) to menu link?
function my_module_entity_base_field_info(\Drupal\Core\Entity\EntityTypeInterface $ entity_type) { if ($ entity_type->id() === 'menu_link_content') { $ fields['location'] = BaseFieldDefinition::create('string') ->setLabel(t('Location')) ->setDisplayOptions('view', ['label' => 'hidden', 'type' => 'string', 'weight' => 0, ]) ->setDisplayOptions('form', array('type' => 'string', 'weight' => 0)); return $ fields; } }
But I am not sure how to go about using hook_update_n to update the schema to reflect this change.
function menu_link_content_update_8201() { 'what do I put here to add the new field that I created'? }
I was able to workaround this issue by manually adding the location
column in the mysql db and I can see the field showing up in the menu link editor and able to load and save it just fine in the cms UI.
But then I am not sure how to access this field in the twig file.
Any help would be grateful. Thanks!