我正在尝试在Drupal 8中的菜单中添加一个新的文本字段,并使用下面的文章中的说明完成了该字段:
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;
}
}但是,我不知道如何使用hook_update_n来更新模式以反映这一变化。
function menu_link_content_update_8201() { 'what do I put here to add the new field that I created'? }我能够通过在mysql db中手动添加location列来解决这个问题,我可以看到这个字段显示在菜单链接编辑器中,并且能够在cms UI中加载和保存它。
但是,我不知道如何访问小枝文件中的这个字段。
任何帮助都会很感激的。谢谢!
发布于 2018-02-10 09:27:03
如果您希望在已经使用模块的生产站点上更新模块,则只需要更新挂钩。如果您编写了一个新模块,或者该模块仍在开发中,您可以简单地重新安装该模块。如果您想在开发期间保留数据,请在更改已安装模块的代码后使用drush entity-updates。
https://drupal.stackexchange.com/questions/255512
复制相似问题