12 March 2015 12:13
Отличная статья по теме http://www.monarchdigital.com/blog/2013-08-09/programmatically-creating-fields-drupal-7 . Особенно примечательно то, что в статье описываются все настройки инстанса поля картинки.
И так, вот пример настроек поля картинки:
// Create the field.
$field = array(
'field_name' => $field_name,
'type' => 'image',
);
field_create_field($field);
// Create the instance.
$instance = array(
'field_name' => $field_name,
'entity_type' => 'node',
'bundle' => 'article',
'label' => 'Article Image',
'description' => 'An image for the article.',
'required' => TRUE,
'settings' => array(
'file_extensions' => 'png jpg jpeg',
'file_directory' => '',
'max_filesize' => '20 MB',
'alt_field' => 1,
'title_field' => 1,
'max_resolution' => '300x200',
'min_resolution' => '200x125',
'default_image' => 0
),
'display' => array(
'default' => array(
'label' => 'hidden',
'type' => 'lightbox2__lightbox__large__original',
'weight' => 0,
'settings' => array(),
'module' => 'lightbox2'
),
'full' => array(
'label' => 'hidden',
'type' => 'imagefield__lightbox2__large__original',
'weight' => 0
),
'teaser' => array(
'label' => 'hidden',
'type' => 'image',
'weight' => 0,
'settings' => array(),
'module' => 'image'
)
)
);
field_create_instance($instance);
Разберем настройки виджета: