cck

Creating A Set Of Fields In One Swell Foop

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.

Subscribe to RSS - cck