You are here

13 December 2011

How you can add field to an entity programmatically in Drupal 7.

Source code viewer
  1. field_create_field(array(
  2. 'field_name' => 'field1',
  3. 'cadinality' => 1,
  4. 'type' => 'number_integer', //number_decimal, text_long, text
  5. ));
  6. field_create_instance(array(
  7. 'field_name' => 'field1',
  8. 'label' => 'this is an instance for field 1',
  9. 'entity_type' => 'imported_tables',
  10. 'bundle' => 'bundle_name',
  11. ));
Programming Language: PHP