How to save content type before saving an exported view through code? I am using a module that defines a content type and view. When I install my module, the view is saved before the content type. So, my view states that fields of that content type are not available.

Is there any way to save content type first and then view?

.install

function _productcustomtype_installed_fields() {
    $t = get_t();
    return array(
        'example_date' =&gt; array(
            'field_name' =&gt; 'example_date',
            'label' =&gt; $t('example Date'),
            'type' =&gt; 'date'
        ),
        'example_slot' =&gt; array(
            'field_name' =&gt; 'example_slot',
            'label' =&gt; $t('example Slot '),
            'type' =&gt; 'list_text'
        )
    );
}


function _productcustomtype_installed_instances() {
    $t = get_t();
    return array(
        'example_date' =&gt; array(
            'field_name' =&gt; 'example_date',
            'type' =&gt; 'text',
            'label' =&gt; $t('example Date'),
            'widget' =&gt; array(
                'type' =&gt; 'date_popup'
            ),
            'date_format' =&gt; 'Y-m-d',
            'display' =&gt; array(
                'default' =&gt; array(
                    'label' =&gt; $t('example Date'),
                    'type' =&gt; 'date_popup'
                )
            )
        ),
        'example_slot' =&gt; array(
            'field_name' =&gt; 'example_slot',
            'type' =&gt; 'text',
            'label' =&gt; $t('example Slot'),
            'widget' =&gt; array(
                'type' =&gt; 'list_text'
            ),
            'display' =&gt; array(
                'default' =&gt; array(
                    'label' =&gt; $t('example Slot'),
                    'type' =&gt; 'list_text'
                )
            )
        )
    );
}

function add_custom_fields() {
    foreach (_productcustomtype_installed_fields() as $field) {
        field_create_field($field);
    }
    foreach (_productcustomtype_installed_instances() as $fieldinstance) {
        $fieldinstance['entity_type'] = 'node';
        $fieldinstance['bundle'] = 'example_calendar';
        print_r($fieldinstance);
        field_create_instance($fieldinstance);
    }
}

function example_install() {
    node_types_rebuild();
    $types = node_type_get_types();
    add_custom_fields();
}


.module file

/**
 * 
 * @return type
 * Implements hook_node_info
 */
function example_node_info() {
  return array(
    'example_calendar' =&gt; array(
      'name' =&gt; t('example Calendar'),
      'base' =&gt; 'example',
      'description' =&gt; t('A example content type'),
      'has_title' =&gt; TRUE,
      'locked' =&gt; FALSE,
    ),
  );
}

/**
 * 
 * @param type $node
 * @param type $form_state
 * @return type
 * Implements hook_form
 */
function example_form($node, $form_state) {
  $type = node_type_get_type($node);
  $form['title'] = array(
    '#type' =&gt; 'textfield',
    '#title' =&gt; check_plain($type-&gt;title_label),
    '#default_value' =&gt; !empty($node-&gt;title) ? $node-&gt;title : '',
    '#required' =&gt; TRUE, '#weight' =&gt; -5
  );

  return $form;
}


/**
 * 
 * @return type
 * Implements hook_views_api
 */
function example_views_api() {
  return array(
    'api' =&gt; 3.0,
  );
}

/**
 * 
 * @return type
 * Implements hook_views_default_views
 */
function example_views_default_views() {
//node View code goes here
}
Change your install function to

$name = 'your content type Machine name';

// Define the node type.
$jobs = array(
'type' =&gt; $name,
'name' =&gt; $t('your content type name'),
'base' =&gt; 'node_content',
'title_label' =&gt; $t(' Title'),
'description' =&gt; $t('Description.'),
'custom' =&gt; TRUE,
);

// Set other node defaults not declared above.
$content_type = node_type_set_defaults($jobs);


Remove node info hook from .module file and start your function name in .module file with your module name.