我想在自定义模块中添加Drupal 8内容类型的额外字段,并且我没有得到任何挂钩。模块挂钩在drupal 8内容类型中添加额外字段
下面是我使用挂钩但这是没有帮助我的结果,我想:
function nodeclass_entity_bundle_field_info(\Drupal\Core\Entity\EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) {
// Add a property only to nodes of the 'article' bundle.
if ($entity_type->id() == 'node' && $bundle == 'article') {
$fields = array();
$fields['mymodule_text_more'] = BaseFieldDefinition::create('string')
->setLabel(t('More text'))
->setComputed(TRUE)
->setClass('\Drupal\mymodule\EntityComputedMoreText');
return $fields;
}
}
没有人在这里回答这个问题? –
这可能还不够,您还需要hook_entity_field_storage_info。 – golddragon007
你也可以看这个:https://drupal.stackexchange.com/questions/220175/add-field-to-bundle-through-hook-entity-bundle-field-info/220177#220177和文件说你需要hook_entity_field_storage_info或者您需要覆盖现有的字段库。你不做这两件事中的任何一件。 – golddragon007