You are here

16 July 2011

Creating content types programmatically in Drupal 7. If you add this code to install hook then this way you can define your own content types in a module for an example.

Source code viewer
  1. $types = array(
  2. 'type' => 'page',
  3. 'name' => st('Page'),
  4. 'base' => 'node_content',
  5. 'description' => st("Use <em>pages</em> for your static content, such as an 'About us' page."),
  6. 'custom' => 1,
  7. 'modified' => 1,
  8. 'locked' => 0,
  9. ),
  10. 'type' => 'article',
  11. 'name' => st('Article'),
  12. 'base' => 'node_content',
  13. 'description' => st('Use <em>articles</em> for time-specific content like news, press releases or blog posts.'),
  14. 'custom' => 1,
  15. 'modified' => 1,
  16. 'locked' => 0,
  17. ),
  18. );
  19.  
  20. foreach ($types as $type) {
  21. $type = node_type_set_defaults($type);
  22. node_type_save($type);
  23. }
Programming Language: PHP