Drupal 7,以编程方式将 field_image 添加到实体
在 Drupal 7 中,我以编程方式创建了一个实体。它以以下形式添加了一些文本字段,例如名称、价格等:
$form['data']['name'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
'#default_value' => isset($model->data['name']) ? $model->data['name']: '',
'#maxlength' => 255,
'#required' => TRUE,
'#weight' => -3,
);
但是,我希望能够向每个实体添加多个图像。
当我使用 Drupal 的用户界面添加字段时,我可以在底部的“添加现有字段”下选择“图像:field_image(图像)”。这个字段正是我想要的行为。
如何以编程方式将其添加到我的实体中?
In Drupal 7 I created an entity programmatically. It has a few textfields added like name, price etc in the form:
$form['data']['name'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
'#default_value' => isset($model->data['name']) ? $model->data['name']: '',
'#maxlength' => 255,
'#required' => TRUE,
'#weight' => -3,
);
However, I'd like to be able to add multiple images to every entity it as well.
When I use Drupal's user interface to add fields, I can pick "Image: field_image (Image)" at the bottom, under "Add an existing field". This field has exactly the behaviour I want.
How can I add it programmatically to my entity?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
HOOK_form_alter()
钩子扩展使用 Drupal UI 创建的内容类型。或者,您可以使用
var_dump();
创建多个图像字段时找出数组生成的内容,并将其添加到自定义模板的数组中。You can just extend the content-type you made with the Drupal UI by using the
HOOK_form_alter()
-hook.Or you can find out what the Array is generating when you make a multiple image-field by using a
var_dump();
and add it to the Array of your custom made template.