2

I created a content type in Drupal programmatically with the following code:

function reservation_system_node_info() {
  $items['add_item'] = array(
    'name' => t('Add a new item'),
    'type' => 'add_item',
    'base' => 'node_content',
    'has_title' => '1',
    'title_label' => t('Name'),
    'help' => t('Please fill in all fields.'),
  );
}

Now I want to add some fields into this content type, but with no luck. I hope someone can help me with this. I tried to use the system_create_instance() function from Drupal. The code I used:

function reservation_system_create_instance() {
  $instance = array(
    'field_name' => 'price_item',
    'label' => 'Price',
    'entity_type' => 'node',
    'bundle' => 'add_item',
  );

field_create_instance($instance);
}

Should I use an another function to create fields in a content type or do I mis something?

  • You can try to use mechanism, which using in module features – Eugene May 21 '15 at 9:22
  • where is the hook_field_info ? – M a m a D May 21 '15 at 9:28
  • Thank you @Eugene, the module features works perfect for me! – Noname May 21 '15 at 9:43

Browse other questions tagged or ask your own question.