diff --git a/includes/uuid_bean.features.inc b/includes/uuid_bean.features.inc index dc34342..db44741 100644 --- a/includes/uuid_bean.features.inc +++ b/includes/uuid_bean.features.inc @@ -9,11 +9,15 @@ */ function uuid_bean_features_export_options() { $options = array(); - if (module_exists("bean_uuid")) { - $query = 'SELECT b.bid, b.title, b.type, b.uuid - FROM {bean} b ORDER BY b.type, b.title ASC'; - $results = db_query($query); - foreach ($results as $bean) { + $types = variable_get('uuid_features_entity_bean', FALSE); + if (module_exists("bean_uuid") && !empty($types)) { + $query = db_select('bean', 'n'); + $query->fields('n', array('bid', 'title', 'type', 'uuid')) + ->condition('type', $types) + ->orderBy('type') + ->orderBy('title'); + $beans = $query->execute()->fetchAll(); + foreach ($beans as $bean) { $options[$bean->uuid] = t('@type: @title', array( '@type' => $bean->type, '@title' => $bean->title, @@ -98,6 +102,9 @@ function uuid_bean_features_export_render($module, $data) { unset($export->changed); unset($export->vid); + // Enable file exports. + uuid_features_file_field_export($export, 'bean'); + // Allow other modules to alter the export rendering. // The hook_alter signature is: // hook_uuid_bean_features_export_render_alter(&$export, $bean, $module); @@ -158,6 +165,8 @@ function uuid_bean_features_rebuild($module) { // Create a new bean. $bean = entity_create('bean', $data); } + // Import the file fields on the bean. + uuid_features_file_field_import($bean, 'bean'); if (!$bean->save()) { drupal_set_message('Failed to create ' . $data['type'] . ' bean ' . $data['label'], 'error'); } diff --git a/includes/uuid_node.features.inc b/includes/uuid_node.features.inc old mode 100755 new mode 100644 index 2cbaa46..ff0e0a7 --- a/includes/uuid_node.features.inc +++ b/includes/uuid_node.features.inc @@ -9,28 +9,23 @@ */ function uuid_node_features_export_options() { $options = array(); - - $types = variable_get('uuid_features_entity_node_types', array_keys(node_type_get_types())); - if (empty($types)) { - return $options; - } - - $query = db_select('node', 'n'); - $query->fields('n', array('nid', 'title', 'type', 'uuid')) - ->condition('type', $types) - ->orderBy('type') - ->orderBy('title'); - $nodes = $query->execute()->fetchAll(); - - foreach ($nodes as $node) { - $options[$node->uuid] = t('@type: @title', array( - '@type' => $types[$node->type], - '@title' => $node->title, - )); + // Check what content types are enabled for uuid features export. + $types = variable_get('uuid_features_entity_node', FALSE); + if (!empty($types)) { + $query = db_select('node', 'n'); + $query->fields('n', array('nid', 'title', 'type', 'uuid')) + ->condition('type', $types) + ->orderBy('type') + ->orderBy('title'); + $nodes = $query->execute()->fetchAll(); + foreach ($nodes as $node) { + $options[$node->uuid] = t('@type: @title', array( + '@type' => $types[$node->type], + '@title' => $node->title, + )); + } } - drupal_alter('uuid_node_features_export_options', $options); - return $options; } diff --git a/includes/uuid_term.features.inc b/includes/uuid_term.features.inc index bf28d9c..a665aa8 100644 --- a/includes/uuid_term.features.inc +++ b/includes/uuid_term.features.inc @@ -9,27 +9,21 @@ */ function uuid_term_features_export_options() { $options = array(); - - $vocabs = variable_get('uuid_features_entity_taxonomy_term_vocabularies', array_keys(taxonomy_vocabulary_get_names())); - if (empty($vocabs)) { - return $options; - } - - $query = db_select('taxonomy_term_data', 't'); - $query->innerJoin('taxonomy_vocabulary', 'v', 't.vid = v.vid'); - $query->condition('v.machine_name', $vocabs) - ->fields('t', array('tid', 'name', 'uuid')) - ->addField('v', 'name', 'vname'); - $query->orderBy('v.name', 'ASC'); - $query->orderBy('t.name', 'ASC'); - $results = $query->execute()->fetchAll(); - - foreach ($results as $term) { - $options[$term->uuid] = $term->vname . ' - ' . $term->name; + $vocabs = variable_get('uuid_features_entity_taxonomy_term', FALSE); + if (!empty($vocabs)) { + $query = db_select('taxonomy_term_data', 't'); + $query->innerJoin('taxonomy_vocabulary', 'v', 't.vid = v.vid'); + $query->condition('v.machine_name', $vocabs) + ->fields('t', array('tid', 'name', 'uuid')) + ->addField('v', 'name', 'vname'); + $query->orderBy('v.name', 'ASC'); + $query->orderBy('t.name', 'ASC'); + $results = $query->execute()->fetchAll(); + foreach ($results as $term) { + $options[$term->uuid] = $term->vname . ' - ' . $term->name; + } } - drupal_alter('uuid_term_features_export_options', $options); - return $options; } diff --git a/uuid_features.module b/uuid_features.module index 87ff964..9b1a33f 100644 --- a/uuid_features.module +++ b/uuid_features.module @@ -15,6 +15,18 @@ function uuid_features_menu() { } /** + * Implements hook_entity_info_alter(). + */ +function uuid_features_entity_info_alter(&$entity_info) { + // Provide a list of entities that provide bundles + // to be exported by uuid_features. + $entity_types = array('bean', 'node', 'taxonomy_term'); + foreach ($entity_types as $type) { + $entity_info[$type]['uuid features'] = TRUE; + } +} + +/** * Implements hook_features_api(). */ function uuid_features_features_api() { @@ -38,7 +50,6 @@ function uuid_features_features_api() { ); } - // Depends on http://drupal.org/node/808690 if (function_exists('uuid_file_insert')) { $components['uuid_file'] = array( 'name' => t('File'), @@ -102,6 +113,7 @@ function uuid_features_features_pipe_taxonomy_alter(&$pipe, $data, $export) { } } } + /** * Menu callback to configure module settings. */ @@ -115,44 +127,27 @@ function uuid_features_settings($form, &$form_state) { ); $entity_info = entity_get_info(); + foreach ($entity_info as $type => $info) { foreach($info['bundles'] as $bundle => $bundle_info) { $bundles[$type][$bundle] = $bundle_info['label']; } + if (isset($info['uuid features']) && $info['uuid features'] === TRUE) { + $form['entity']['uuid_features_entity_' . $type] = array( + '#type' => 'checkboxes', + '#title' => t('Exportable ' . $info['label'] . ' bundles'), + '#default_value' => variable_get('uuid_features_entity_' . $type, array()), + '#options' => $bundles[$type], + ); + $form['file']['uuid_features_file_' . $type] = array( + '#type' => 'checkboxes', + '#title' => t('Files exported for ' . $info['label'] . ' bundles'), + '#default_value' => variable_get('uuid_features_file_' . $type, array()), + '#options' => $bundles[$type], + ); + } } - $form['entity']['uuid_features_entity_node_types'] = array( - '#type' => 'checkboxes', - '#title' => t('Exportable node types'), - '#description' => t('Which content types should be exportable?'), - '#default_value' => variable_get('uuid_features_entity_node_types', array()), - '#options' => $bundles['node'], - ); - - $form['entity']['uuid_features_entity_taxonomy_term_vocabularies'] = array( - '#type' => 'checkboxes', - '#title' => t('Exportable term vocabularies'), - '#description' => t("Which taxonomy vocabulary's terms should be exportable?"), - '#default_value' => variable_get('uuid_features_entity_taxonomy_term_vocabularies', array()), - '#options' => $bundles['taxonomy_term'], - ); - - $form['file']['uuid_features_file_node_types'] = array( - '#type' => 'checkboxes', - '#title' => t('Files exported for nodes'), - '#description' => t('Which content types should export file fields?'), - '#default_value' => variable_get('uuid_features_file_node_types', array()), - '#options' => $bundles['node'], - ); - - $form['file']['uuid_features_file_taxonomy_term_types'] = array( - '#type' => 'checkboxes', - '#title' => t('Files exported for taxonomy terms'), - '#description' => t('Which vocabularies should export file fields?'), - '#default_value' => variable_get('uuid_features_file_taxonomy_term_types', array()), - '#options' => $bundles['taxonomy_term'], - ); - $form['file']['uuid_features_file_mode'] = array( '#type' => 'radios', '#title' => t('File export mode'), @@ -206,6 +201,7 @@ function uuid_features_file_field_export(&$export, $entity_type) { case "taxonomy_term": $export_bundle = $export->vocabulary_machine_name; break; + case "bean": case "node": $export_bundle = $export->type; break; @@ -320,7 +316,7 @@ function uuid_features_file_field_export(&$export, $entity_type) { } } } -//entity_type + /** * Handle importing file fields. */ @@ -329,6 +325,7 @@ function uuid_features_file_field_import(&$import, $entity_type) { case "taxonomy_term": $import_bundle = $import->vocabulary_machine_name; break; + case "bean": case "node": $import_bundle = $import->type; break;