I have theme with custom content types, views, etc. and i would like to package into a custom module so it can be easy installed in another Drupal instance via MODULE_install().
Currently, Module_install() looks something like this:
function MODULE_install(){
$t = get_t();
foreach (_jobs_installed_fields() as $field) {
field_create_field($field);
drupal_set_message($t('Field type: '.$field['field_name'] . ' created'));
}
foreach (_jobs_installed_field_instances() as $field) {
field_create_instance($field);
drupal_set_message($t('Field instance: '.$field['label'].' initiated and added to User Profile'));
}
drupal_set_message($t('Finished adding fields to User profile'));
}
function _jobs_installed_fields() {
return array(
'field_name' => array(
...
),
'field_name2' => array(
...
),
);
}
function _jobs_installed_field_instances() {
return array(
'field_name' => array(
...
),
'field_name2' => array(
...
),
);
}
The content of _jobs_installed_field_instances and _jobs_installed_fields functions is generated via PHP Execute Script Dev module block from the current instance content and then copy/paste in the install script.
$entity_type = 'user';
$field_name = 'field_name';
$bundle_name = 'user';
$info_config = field_info_field($field_name);
$info_instance = field_info_instance($entity_type, $field_name, $bundle_name);
unset($info_config['id']);
unset($info_instance['id'], $info_instance['field_id']);
include_once DRUPAL_ROOT . '/includes/utility.inc';
$output = "field_create_field(" . drupal_var_export($info_config) . ");\n";
$output .= "field_create_instance(" . drupal_var_export($info_instance) . ");";
drupal_set_message("<textarea rows=30 style=\"width: 100%;\">" . $output . '</textarea>')
This can be lot of work for larger Themes and i cannot rerun it later once the change is introduced. I was thinking creating some Php scripts that would generate me the install script from the current nodes, views, etc so i can rerun as like in future. Is there anything like this already available? What would be your approach to this problem? Thank you