summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Davis2012-12-24 16:37:27 (GMT)
committer Ben Davis2012-12-24 16:37:27 (GMT)
commit0824017f938bccf16067d3917ef7fafceb4319ad (patch)
treecd82bd488c8fb329a2c9fa9dca86bcf41b2f6cdd
parent57372169c6f651c18856aa81d8b1c606918668bd (diff)
Issue #1789162 by 10oclock: Weight settings imported via Features not respected.
-rw-r--r--weight.features.inc61
-rw-r--r--weight.install13
-rw-r--r--weight.module33
3 files changed, 94 insertions, 13 deletions
diff --git a/weight.features.inc b/weight.features.inc
new file mode 100644
index 0000000..d596178
--- /dev/null
+++ b/weight.features.inc
@@ -0,0 +1,61 @@
+<?php
+
+/**
+ * Implements hook_features_export_options().
+ */
+function weight_features_export_options() {
+ $settings = array_keys(_weight_get_settings());
+ return drupal_map_assoc($settings);
+}
+
+/**
+ * Implements hook_features_export().
+ */
+function weight_features_export($data, &$export, $module_name = '') {
+ $export['dependencies']['features'] = 'features';
+ $export['dependencies']['weight'] = 'weight';
+
+ foreach ($data as $setting) {
+ $export['features']['weight'][$setting] = $setting;
+ }
+
+ return $export;
+}
+
+/**
+ * Implements hook_features_export_render().
+ */
+function weight_features_export_render($module, $data) {
+ $code = array();
+ $code[] = ' $settings = array();';
+ $code[] = '';
+
+ foreach ($data as $name) {
+ if ($settings = _weight_get_settings($name)) {
+ $settings_export = features_var_export($settings, ' ');
+ $code[] = " \$settings['{$name}'] = {$settings_export};";
+ $code[] = "";
+ }
+ }
+
+ $code[] = ' return $settings;';
+ $code = implode("\n", $code);
+
+ return array('weight_features_default_settings' => $code);
+}
+
+/**
+ * Implements hook_features_revert().
+ */
+function weight_features_revert($module) {
+ weight_features_rebuild($module);
+}
+
+/**
+ * Implements hook_features_rebuild().
+ */
+function weight_features_rebuild($module) {
+ if ($settings = features_get_default('weight', $module)) {
+ weight_settings_save($settings);
+ }
+}
diff --git a/weight.install b/weight.install
index c9d0f24..d02891f 100644
--- a/weight.install
+++ b/weight.install
@@ -6,19 +6,6 @@
function weight_schema() {
$schema['weight_settings'] = array(
'description' => 'Table for storing Weight configuration',
- 'export' => array(
- 'key' => 'type',
- 'key name' => 'Type',
- 'primary key' => 'type',
- 'identifier' => 'settings',
- 'export type string' => 'export_type',
- 'api' => array(
- 'owner' => 'weight',
- 'api' => 'weight',
- 'minimum_version' => 1,
- 'current_version' => 1,
- ),
- ),
'fields' => array(
'id' => array(
'description' => 'The primary identifier for a content type configuration',
diff --git a/weight.module b/weight.module
index 2e4d5f9..076d7ab 100644
--- a/weight.module
+++ b/weight.module
@@ -375,6 +375,20 @@ function weight_menu_link_update($link) {
}
/**
+ * Implements hook_features_api().
+ */
+function weight_features_api() {
+ return array(
+ 'weight' => array(
+ 'name' => 'Weight',
+ 'file' => drupal_get_path('module', 'weight') . '/weight.features.inc',
+ 'default_hook' => 'weight_features_default_settings',
+ 'feature_source' => TRUE,
+ ),
+ );
+}
+
+/**
* Implements hook_views_api().
*/
function weight_views_api() {
@@ -439,6 +453,25 @@ function weight_apachesolr_query_prepare($query) {
}
/**
+ * Saves Weight settings for a node type.
+ */
+function weight_settings_save($settings) {
+ foreach ($settings as $type => $setting) {
+ db_merge('weight_settings')
+ ->key(array('type' => $type))
+ ->fields(array(
+ 'type' => $type,
+ 'weight_enabled' => $setting['enabled'],
+ 'weight_range' => $setting['range'],
+ 'menu_weight' => $setting['menu_weight'],
+ 'weight_default' => $setting['default'],
+ 'sync_translations' => $setting['sync_translations'],
+ ))
+ ->execute();
+ }
+}
+
+/**
* Set the weight of a node.
*/
function _weight_set_weight($node) {