【发布时间】:2016-05-06 08:10:46
【问题描述】:
我想在 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。
-
您也可以观看:drupal.stackexchange.com/questions/220175/… 并且文档说您需要 hook_entity_field_storage_info 或者您需要覆盖现有的字段库。你不做这两个中的任何一个。