You are here

function _map_widget_map_fixer in Map Widget 8

Helper function to untangle corrupted maps.

Parameters

array $munged_maps: The tangled data.

Return value

array The untangled data.

1 call to _map_widget_map_fixer()
map_widget_update_8101 in ./map_widget.install
Untangles recursively nested map data.

File

./map_widget.install, line 56
Install, update and uninstall functions for the map_widget module.

Code

function _map_widget_map_fixer(array $munged_maps) {
  $fixed_maps = [];
  $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($munged_maps), RecursiveIteratorIterator::SELF_FIRST);
  foreach ($iterator as $key => $value) {

    // Check for possible normal entry.
    if (is_array($value)) {
      if (isset($value['key']) && isset($value['value']) && !isset($fixed_maps[$value['key']])) {
        $fixed_maps[$value['key']] = $value['value'];
      }
    }
    else {

      // Possible normal entry.
      if ($value == 'value' || $key == 'key') {

        // Processed at a higher level of the iterator.
        continue;
      }
      if (!isset($fixed_maps[$key])) {
        $fixed_maps[$key] = $value;
      }
    }
  }

  // If our repair didn't harvest anything, return the original to prevent loss.
  return empty($fixed_maps) ? $munged_maps : $fixed_maps;
}