function _patterns_rearrange_data in Patterns 5
Same name and namespace in other branches
- 6.2 patterns.module \_patterns_rearrange_data()
- 6 patterns.module \_patterns_rearrange_data()
1 call to _patterns_rearrange_data()
File
- ./
patterns.module, line 1200 - Enables extremely simple adding/removing features to your site with minimal to no configuration
Code
function _patterns_rearrange_data($data, $parent = '') {
$numeric = array();
$count = 0;
foreach ($data as $key => $value) {
if ($value['value'] == 'false') {
$value['value'] = false;
}
else {
if ($value['value'] == 'true') {
$value['value'] = true;
}
}
if (is_numeric($key) && is_array($value) && count($value) == 2 && isset($value['tag']) && isset($value['value'])) {
unset($data[$key]);
if (isset($data[$value['tag']])) {
$numeric[] = $value['tag'];
$data[$count++] = $data[$value['tag']];
$data[$count++] = $value['value'];
unset($data[$value['tag']]);
}
else {
if (in_array($value['tag'], $numeric)) {
$data[$count++] = $value['value'];
}
else {
$data[$value['tag']] = $value['value'];
}
}
}
else {
if (is_numeric($key)) {
$tag = $value['tag'];
unset($value['tag']);
$data[$tag][] = _patterns_rearrange_data($value, $tag);
unset($data[$key]);
}
}
}
foreach ($data as $key => $value) {
if (is_array($value) && count($value) == 1 && $value[0]) {
$data[$key] = $data[$key][0];
}
}
return $data;
}