phpdrupaldrupal-7drupal-modulesdrupal-content-types

Convert drupal 7 content type into code automatically. Content type generator code?


I already have a content type in my drupal project.

I am currently working on my own module and would like to create a built in content type. Is there a way to convert a content type that I built directly in drupal into code ? A kind of Content Type Code Generator ?.

I want to generate this code automatically if it's possible.

$t = get_t();

  // Define the node type.
  $slider = array(
    'type' => 'slider',
    'name' => $t('Slider Content'),
    'base' => 'node_content',
    'description' => $t('This is an example node type with a few fields.'),
    'body_label' => $t('Example Description')
  );

  // Complete the node type definition by setting any defaults not explicitly
  // declared above.
  // http://api.drupal.org/api/function/node_type_set_defaults/7
  $content_type = node_type_set_defaults($slider);
  node_add_body_field($content_type);

  // Save the content type
  node_type_save($content_type);

Thanks a lot.


Solution

  • Maybe you should have a look at Features module. Using Features should allow you to export your content type along with added fields into a module you can install to another site later.

    Check this documentation link.