diff --git a/hansel.export.inc b/hansel.export.inc index 15f922ed9bba67cfba9355a5ac51d3921bf4d4f1..37e46bc2627c502cc0f1da3977c59be6f46c7862 100644 --- a/hansel.export.inc +++ b/hansel.export.inc @@ -6,7 +6,39 @@ * @return array */ function hansel_export_config() { - return hansel_get_config(); + $config = hansel_get_config(); + $mapping = array(); + + $export = array( + 'version' => $config['version'], + 'start_rid' => 0, + 'rules' => array(), + 'nodetypes' => $config['nodetypes'], + ); + + // Copy rules and renumber them. + $id = 0; + foreach ($config['rules'] as $rule) { + ++$id; + $mapping[$rule->rid] = $id; + $rule->rid = $id; + $export['rules'][$id] = clone $rule; + } + + // Map start rule. + $export['start_rid'] = $mapping[$config['start_rid']]; + + // Map parents and destinations. + foreach ($export['rules'] as $id => $rule) { + if ($rule->pid) { + $export['rules'][$id]->pid = $mapping[$rule->pid]; + } + if ($rule->action == 'goto') { + $export['rules'][$id]->destination = $mapping[$rule->destination]; + } + } + + return $export; } /** @@ -27,7 +59,7 @@ function hansel_import_config($config) { // Store all rules without actions and parent id's first, we will update // those later cause we don't have a complete mapping here. foreach ($config['rules'] as $rule) { - if (is_array($rule)) { + if (is_array($rule)) { // The input can be an array because we use features_var_export(). $rule = (object) $rule; }