Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PaymentSectionModifier.php
Go to the documentation of this file.
1 <?php
7 
12 {
18  private static $specialGroups = [
19  'account',
20  'recommended_solutions',
21  'other_paypal_payment_solutions',
22  'other_payment_methods',
23  ];
24 
41  public function modify(array $initialStructure)
42  {
43  $changedStructure = array_fill_keys(self::$specialGroups, []);
44 
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'])) {
50  $children += $childData['children'];
51  }
52  $childData['children'] = $children;
53  unset($children);
54  }
55  $changedStructure[$childSection] = $childData;
56  } else {
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']);
62  $changedStructure
63  [$moveInstruction['parent']]
64  ['children']
65  [$moveInstruction['section']] = $moveInstruction['data'];
66  }
67  }
68  if (!isset($moveInstructions[$childSection])) {
69  $changedStructure['other_payment_methods']['children'][$childSection] = $childData;
70  }
71  }
72  }
73 
74  return $changedStructure;
75  }
76 
84  private function getMoveInstructions($section, $data)
85  {
86  $moved = [];
87 
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]);
93  }
94  $moved = array_merge($moved, $movedChildren);
95  }
96  }
97 
98  if (isset($data['displayIn']) && in_array($data['displayIn'], self::$specialGroups)) {
99  $moved = array_merge(
100  [
101  $section => [
102  'parent' => $data['displayIn'],
103  'section' => $section,
104  'data' => $data
105  ]
106  ],
107  $moved
108  );
109  }
110 
111  return $moved;
112  }
113 }
$children
Definition: actions.phtml:11