From c1a192459613d051865c4e4c40389fbf40bc6459 Mon Sep 17 00:00:00 2001
From: Dave Hall <dave.hall@skwashd.com>
Date: Thu, 29 Aug 2013 12:22:31 +1000
Subject: [PATCH] Issue #2076543 by skwashd: Add hooks for altering values on
 import and export

---
 strongarm.api.php | 39 +++++++++++++++++++++++++++++++++++++++
 strongarm.module  |  4 ++++
 2 files changed, 43 insertions(+)
 create mode 100644 strongarm.api.php

diff --git a/strongarm.api.php b/strongarm.api.php
new file mode 100644
index 0000000..a0d746a
--- /dev/null
+++ b/strongarm.api.php
@@ -0,0 +1,39 @@
+<?php
+
+/**
+ * @file
+ * Strongarm API functions.
+ */
+
+/**
+ * Alter the value of variable when it is being exported.
+ *
+ * @param mixed $value
+ *   The value being exported.
+ * @param string $name
+ *   The name of the variable being exported
+ */
+function hook_strongarm_export_value_alter(&$value, $name) {
+  if ('user_admin_role' == $name) {
+    $role = user_role_load($value);
+    $value = $role->name;
+  }
+}
+
+/**
+ * Alter the value of variable when it is being imported.
+ *
+ * @param mixed $value
+ *   The value being exported.
+ * @param string $name
+ *   The name of the variable being exported
+ */
+function hook_strongarm_import_value_alter(&$value, $name) {
+  if ('user_admin_role' == $name) {
+    $role = user_role_load_by_name($value);
+    $value = NULL;
+    if ($role) {
+      $value = $role->rid;
+    }
+  }
+}
diff --git a/strongarm.module b/strongarm.module
index c8b1e2a..7be4596 100644
--- a/strongarm.module
+++ b/strongarm.module
@@ -116,6 +116,7 @@ if (!function_exists('variable_features_revert')) {
     $vars = strongarm_vars_load(TRUE, TRUE);
     foreach ($defaults as $name => $default) {
       if (!empty($vars[$name]->in_code_only) || ($default->value !== $vars[$name]->value)) {
+        drupal_alter('strongarm_import_value', $default->value, $name);
         variable_set($name, $default->value);
       }
     }
@@ -135,6 +136,7 @@ function variable_features_rebuild($module) {
   $vars = strongarm_vars_load(TRUE, TRUE);
   foreach ($defaults as $name => $default) {
     if (!empty($vars[$name]->in_code_only) || (drupal_installation_attempted() && $vars[$name]->export_type & EXPORT_IN_CODE)) {
+      drupal_alter('strongarm_import_value', $default->value, $name);
       variable_set($name, $default->value);
     }
   }
@@ -157,6 +159,7 @@ function variable_features_export($data, &$export, $module_name) {
   foreach ($data as $object_name) {
     if (!isset($vars[$object_name]) || !empty($vars[$object_name]->in_code_only)) {
       unset($export['features']['variable'][$object_name]);
+      continue;
     }
   }
   return $pipe;
@@ -179,6 +182,7 @@ function variable_features_export_render($module, $data) {
     ->execute();
   foreach ($result as $object) {
     $object = _ctools_export_unpack_object($schema, $object);
+    drupal_alter('strongarm_export_value', $object->value, $object->name);
     $code .= _ctools_features_export_crud_export('variable', $object, '  ');
     $code .= "  \$export[" . ctools_var_export($object->name) . "] = \${$identifier};\n\n";
   }
-- 
1.8.2.3

