是否可以在自定义字段中添加对媒体类型的实体引用?
例如-我有一个需要图像的自定义字段。 这是my_module / src / plugin / Field / FieldType / MyFieldType.php和模式中自定义字段的属性定义的当前状态。
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
$properties = parent::propertyDefinitions($field_definition);
$properties['icon_id'] = DataReferenceDefinition::create('entity')
->setLabel('Image')
->setDescription(new TranslatableMarkup('The referenced entity image'))
->setComputed(TRUE)
->setReadOnly(FALSE)
->setTargetDefinition(EntityDataDefinition::create('media'));
return $properties;
}
public static function schema(FieldStorageDefinitionInterface $field_definition) {
$schema = parent::schema($field_definition);
$schema['columns']['icon_id'] = [
'description' => 'The icon ID',
'type' => 'int',
'unsigned' => TRUE,
];
return $schema;
}