Skip to main content
Joachim's blog

Main navigation

  • Home
  • About

Breadcrumb

  1. Home

Creating A Set Of Fields In One Swell Foop

By joachim, Wed, 04/11/2009 - 15: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.

Tags

  • drupal
  • 6.x
  • cck
  • drupal planet

Frequent tags

  • Drupal Code Builder (9)
  • git (7)
  • module builder (6)
  • 6.x (5)
  • drupal commerce (4)
  • patching (3)
  • Composer (3)
  • Drush (3)
  • development (3)
  • Entity API (3)
  • Field API (3)
  • Drupal core (2)
  • core (2)
  • issue queue (2)
  • modules (2)
  • roadmap (2)
  • 7.x (2)
  • developer tools (2)
  • Rector (2)
  • wtf (2)
  • contributing code (2)
  • code style (2)
  • contrib module (2)
  • maintaining projects (2)
  • debugging (2)
  • drupal.org (2)
  • tests (2)
  • multisite (2)
Powered by Drupal