Drupal 8,'托管文件的默认值'字段

时间:2015-12-04 09:29:55

标签: drupal-forms drupal-8

我通过自定义模块创建了一个(节点的)编辑自定义表单。从这个表单中,我有一个"托管文件"字段(对于一张图片)我将其默认值设置为fid; 但是,当我的表单被渲染时,"托管文件"字段不显示鼠标图像。我不明白为什么:/

我的代码:

$form['project']['image'] = array(
  '#type' => 'managed_file',
  '#title' => t('Image'),
  '#default_value' => 10, //Set 10 for the test, the fid "10" exist, I checked
);

我的表单已呈现:

[enter image description here]

如您所见,没有加载图像,而default_value设置为现有的fid(10)

1

1 个答案:

答案 0 :(得分:3)

要渲染现有图片,请使用以下代码

$form['project']['image'] = array( 
  '#type' => 'managed_file', 
  '#title' => t('Image'), 
  '#default_value' => array(10), 
);

你需要以数组格式提供fid。