18 private static $specialGroups = [
20 'recommended_solutions',
21 'other_paypal_payment_solutions',
22 'other_payment_methods',
41 public function modify(array $initialStructure)
43 $changedStructure = array_fill_keys(self::$specialGroups, []);
45 foreach ($initialStructure as $childSection => $childData) {
46 if (in_array($childSection, self::$specialGroups)) {
47 if (isset($changedStructure[$childSection][
'children'])) {
48 $children = $changedStructure[$childSection][
'children'];
49 if (isset($childData[
'children'])) {
55 $changedStructure[$childSection] = $childData;
57 $moveInstructions = $this->getMoveInstructions($childSection, $childData);
58 if (!empty($moveInstructions)) {
59 foreach ($moveInstructions as $moveInstruction) {
60 unset($childData[
'children'][$moveInstruction[
'section']]);
61 unset($moveInstruction[
'data'][
'displayIn']);
63 [$moveInstruction[
'parent']]
65 [$moveInstruction[
'section']] = $moveInstruction[
'data'];
68 if (!isset($moveInstructions[$childSection])) {
69 $changedStructure[
'other_payment_methods'][
'children'][$childSection] = $childData;
74 return $changedStructure;
84 private function getMoveInstructions($section,
$data)
88 if (array_key_exists(
'children',
$data)) {
89 foreach (
$data[
'children'] as $childSection => $childData) {
90 $movedChildren = $this->getMoveInstructions($childSection, $childData);
91 if (isset($movedChildren[$childSection])) {
92 unset(
$data[
'children'][$childSection]);
94 $moved = array_merge($moved, $movedChildren);
98 if (isset(
$data[
'displayIn']) && in_array(
$data[
'displayIn'], self::$specialGroups)) {
102 'parent' =>
$data[
'displayIn'],
103 'section' => $section,
modify(array $initialStructure)