You are here

function _macro_recursively_convert_objects_to_arrays in Macro 7

Same name and namespace in other branches
  1. 6 macro.module \_macro_recursively_convert_objects_to_arrays()

This recursively runs thru an object and converts it into an array. This is to be called for form entries as we do not want varexport to treat any element as an object. If varexport sees an object, it will output stdClass::__set_state, which is not defined and we cannot define it either. So we recursively cast all objects to arrays.

1 call to _macro_recursively_convert_objects_to_arrays()
macro_get_macro in ./macro.module
The output of this callback should be saved to the profiles/$profile/macros.inc file, to be automatically played back upon completed install.

File

./macro.module, line 231
allow administrators to record (export) form submissions allow administrators to replay (import) form submissions

Code

function _macro_recursively_convert_objects_to_arrays($entity) {
  $converted = array();
  foreach ((array) $entity as $key => $value) {
    if (is_array($value) || is_object($value)) {
      $converted[$key] = _macro_recursively_convert_objects_to_arrays($value);
    }
    else {
      $converted[$key] = $value;
    }
  }
  return $converted;
}