Creating A Set Of Fields In One Swell Foop
Submitted by joachim.noreiko on Wed, 04/11/2009 - 16:19
Situation: you need a heap of imagefields that more or less have the same setup. Let's not go into why.
You could spend half an hour bored witless clicking through the interface.
Or you could create just the one field, export the content type with content copy, and then doctor the code a little before importing it back in. Like this....
<?php
// The usual content type stuff here.
// Set of image fields
$image_fields = array(
'field_image_1' => 'Image 1',
'field_image_2' => 'Image 2',
// etc
);
foreach ($image_fields as $name => $label) {
$content['fields'][] = array (
'label' => $label,
'field_name' => $name,
'type' => 'filefield',
'widget_type' => 'imagefield_widget',
'change' => 'Change basic information',
'weight' => '-3',
// the rest of your field export code here
// don't forget to fix the brackets, as export code
// comes out as a numerically keyed array.
// and don't forget the closing }!
?>Hey presto, heap of fields created in one go. Don't forget to set their weights nicely afterwards.


You could also set the image
You could also set the image field to allow/require 6 images.
If only! Clients want more
If only!
Clients want more control than that.
Cool, thanks for sharing
I could have used this code about a month ago. I had to create 6 similar image fields.
Post new comment