0
votes

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?

1

1 Answers

0
votes

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.