← All changes
|
modules/global-classes/utils/template-library-global-classes-snapshot-builder.php
+14
-20
4.2.0-dev2
→
4.1.0-beta1
View file →
| @@ -175,33 +175,27 @@ | ||
| 175 | 175 | protected function save_data( array $data, array $metadata ): array { |
| 176 | 176 | $new_items = $data['new_items'] ?? []; |
| 177 | 177 | $order = $data['order'] ?? []; |
| 178 | 178 | |
| 179 | - if ( empty( $new_items ) ) { | |
| 180 | - return [ | |
| 181 | - 'global_classes' => [ | |
| 182 | - 'added_items' => [], | |
| 183 | - 'added_items_order' => [], | |
| 179 | + if ( ! empty( $new_items ) ) { | |
| 180 | + $repository = Global_Classes_Repository::make()->set_preview( false ); | |
| 181 | + | |
| 182 | + $added_ids = array_keys( $new_items ); | |
| 183 | + | |
| 184 | + $repository->apply_changes( | |
| 185 | + $new_items, | |
| 186 | + [ | |
| 187 | + 'added' => $added_ids, | |
| 188 | + 'order' => true, | |
| 184 | 189 | ], |
| 185 | - ]; | |
| 190 | + $order | |
| 191 | + ); | |
| 186 | 192 | } |
| 187 | 193 | |
| 188 | - $repository = Global_Classes_Repository::make()->set_preview( false ); | |
| 189 | - $added_ids = array_keys( $new_items ); | |
| 190 | - | |
| 191 | - $repository->apply_changes( | |
| 192 | - $new_items, | |
| 193 | - [ | |
| 194 | - 'added' => $added_ids, | |
| 195 | - 'order' => true, | |
| 196 | - ], | |
| 197 | - $order | |
| 198 | - ); | |
| 199 | - | |
| 200 | 194 | return [ |
| 201 | 195 | 'global_classes' => [ |
| 202 | - 'added_items_order' => $added_ids, | |
| 203 | - 'added_items' => $new_items, | |
| 196 | + 'items' => $data['updated_items'] ?? [], | |
| 197 | + 'order' => $order, | |
| 204 | 198 | ], |
| 205 | 199 | ]; |
| 206 | 200 | } |
| 207 | 201 | |