diff --git a/commerce_checkout_panes.features.inc b/commerce_checkout_panes.features.inc new file mode 100644 index 0000000..60bc73a --- /dev/null +++ b/commerce_checkout_panes.features.inc @@ -0,0 +1,108 @@ + $pane) { + $options[$pane_id] = sprintf('%s (%s)', $pane['title'], $pane['name']); + } + + return $options; +} + +/** + * Implements hook_features_export(). + */ +function commerce_checkout_panes_features_export(array $data, array &$export, $module_name) { + $panes = commerce_checkout_panes(); + + foreach ($data as $pane_id) { + $export['features'][COMMERCE_CHECKOUT_PANES_INTEGRATION_NAME][$pane_id] = $pane_id; + $export['dependencies'][] = $panes[$pane_id]['module']; + } + + return array(); +} + +/** + * Implements hook_features_export_render(). + */ +function commerce_checkout_panes_features_export_render($module_name, array $data, $export = NULL) { + // Need to reset static cache, otherwise Features will not be able to check + // a state of components properly. + commerce_checkout_panes_reset(); + + $schema = drupal_get_schema('commerce_checkout_pane'); + $fields = array_fill_keys(array_keys($schema['fields']), NULL); + $panes = commerce_checkout_panes(); + $code = array(); + + $code[] = ' $panes = array();'; + + foreach ($data as $pane_id) { + if (isset($panes[$pane_id])) { + $code[] = ''; + $code[] = sprintf(' $panes[%s] = %s;', "'$pane_id'", features_var_export(array_intersect_key($panes[$pane_id], $fields), ' ')); + } + } + + $code[] = ''; + $code[] = ' return $panes;'; + + return array(COMMERCE_CHECKOUT_PANES_DEFAULT_HOOK => implode("\n", $code)); +} + +/** + * Implements hook_features_revert(). + */ +function commerce_checkout_panes_features_revert($module_name) { + $defaults = module_invoke($module_name, COMMERCE_CHECKOUT_PANES_DEFAULT_HOOK); + + if (!empty($defaults)) { + commerce_checkout_panes_reset(); + $existing = commerce_checkout_panes(); + + foreach ($defaults as $pane_id => $pane) { + $pane['saved'] = isset($existing[$pane_id]['saved']) ? $existing[$pane_id]['saved'] : FALSE; + + commerce_checkout_pane_save($pane); + } + } +} + +/** + * Implements hook_features_rebuild(). + */ +function commerce_checkout_panes_features_rebuild($module_name) { + commerce_checkout_panes_features_revert($module_name); +} + +/** + * Implements hook_features_enable_feature(). + */ +function commerce_checkout_panes_features_enable_feature($module) { + commerce_checkout_panes_features_revert($module); +} + +/** + * Implements hook_features_disable_feature(). + */ +function commerce_checkout_panes_features_disable_feature($module) { + $defaults = module_invoke($module, COMMERCE_CHECKOUT_PANES_DEFAULT_HOOK); + + if (!empty($defaults)) { + foreach ($defaults as $pane_id => $pane) { + commerce_checkout_pane_reset($pane_id); + } + } +} diff --git a/commerce_features.module b/commerce_features.module index b4bfb33..685c136 100644 --- a/commerce_features.module +++ b/commerce_features.module @@ -10,43 +10,34 @@ */ function commerce_features_features_api() { $features = array(); + $path = drupal_get_path('module', 'commerce_features'); if (module_exists('commerce_product') && module_exists('commerce_product_ui')) { $features['commerce_product_type'] = array( 'name' => t('Commerce product types'), - 'feature_source' => TRUE, 'default_hook' => 'commerce_product_default_types', - 'file' => drupal_get_path('module', 'commerce_features') . '/commerce_product_type.features.inc', ); } if (module_exists('commerce_tax')) { $features['commerce_tax_type'] = array( 'name' => t('Commerce tax types'), - 'feature_source' => TRUE, 'default_hook' => 'commerce_tax_default_types', - 'file' => drupal_get_path('module', 'commerce_features') . '/commerce_tax_type.features.inc', ); $features['commerce_tax_rate'] = array( 'name' => t('Commerce tax rates'), - 'feature_source' => TRUE, 'default_hook' => 'commerce_tax_default_rates', - 'file' => drupal_get_path('module', 'commerce_features') . '/commerce_tax_rate.features.inc', ); } if (module_exists('commerce_order') && module_exists('commerce_order_types')) { $features['commerce_order_type'] = array( 'name' => t('Commerce order types'), - 'features_source' => TRUE, 'default_hook' => 'commerce_order_default_types', - 'file' => drupal_get_path('module', 'commerce_features') . '/commerce_order_type.features.inc', ); } if (module_exists('commerce_line_item') && module_exists('commerce_custom_product')) { $features['commerce_line_item_type'] = array( 'name' => t('Commerce line item types'), - 'feature_source' => TRUE, 'default_hook' => 'commerce_line_item_default_types', - 'file' => drupal_get_path('module', 'commerce_features') . '/commerce_line_item_type.features.inc', ); } if (module_exists('commerce_coupon')) { @@ -54,34 +45,40 @@ function commerce_features_features_api() { if (version_compare($module_info['version'], '7.x-2', '<')) { $features['commerce_coupon_type'] = array( 'name' => t('Commerce coupon types'), - 'feature_source' => TRUE, 'default_hook' => 'commerce_coupon_default_types', - 'file' => drupal_get_path('module', 'commerce_features') . '/commerce_coupon_type.features.inc', ); } } if (module_exists('commerce_customer')) { $features['commerce_customer'] = array( 'name' => t('Commerce customer profile types'), - 'features_source' => TRUE, 'default_hook' => 'commerce_customer_default_types', - 'file' => drupal_get_path('module', 'commerce_features') . '/commerce_customer.features.inc', ); } if (module_exists('commerce_flat_rate')) { $features['commerce_flat_rate_services'] = array( 'name' => t('Commerce flat rate services'), - 'features_source' => TRUE, 'default_hook' => 'commerce_flat_rate_default_services', - 'file' => drupal_get_path('module', 'commerce_features') . '/commerce_flat_rate_services.features.inc', ); } if (module_exists('commerce_payment')) { $features['commerce_payment_method'] = array( 'name' => t('Commerce payment methods'), - 'features_source' => TRUE, 'default_hook' => 'commerce_payment_default_methods', - 'file' => drupal_get_path('module', 'commerce_features') . '/commerce_payment_method.features.inc', + ); + } + if (module_exists('commerce_checkout')) { + $features['commerce_checkout_panes'] = array( + 'name' => t('Commerce checkout panes'), + 'default_hook' => 'commerce_checkout_panes_default', + 'default_file' => FEATURES_DEFAULTS_INCLUDED, + ); + } + + foreach ($features as $name => $integration) { + $features[$name] = $integration + array( + 'file' => "$path/$name.features.inc", + 'feature_source' => TRUE, ); }