|
3 | 3 | * Copyright © Magento, Inc. All rights reserved.
|
4 | 4 | * See COPYING.txt for license details.
|
5 | 5 | */
|
| 6 | +declare(strict_types=1); |
| 7 | + |
6 | 8 | namespace Magento\Ui\Controller\Adminhtml\Bookmark;
|
7 | 9 |
|
8 | 10 | use Magento\Authorization\Model\UserContextInterface;
|
@@ -246,17 +248,32 @@ private function updateCurrentBookmarkConfig(array $data): void
|
246 | 248 | $bookmarkConfig = $bookmark->getConfig();
|
247 | 249 | $existingConfig = $bookmarkConfig['views'][$bookmark->getIdentifier()]['data'] ?? null;
|
248 | 250 | $currentConfig = $data[self::CURRENT_IDENTIFIER] ?? null;
|
249 |
| - if ($existingConfig && $currentConfig) { |
250 |
| - if ($existingConfig['filters'] === $currentConfig['filters'] |
251 |
| - && $existingConfig['positions'] !== $currentConfig['positions'] |
252 |
| - ) { |
253 |
| - $bookmarkConfig['views'][$bookmark->getIdentifier()]['data'] = $data[self::CURRENT_IDENTIFIER]; |
254 |
| - $bookmark->setConfig($this->serializer->serialize($bookmarkConfig)); |
255 |
| - $this->bookmarkRepository->save($bookmark); |
256 |
| - } |
| 251 | + if ($existingConfig && $currentConfig && $this->isPositionChanged($existingConfig, $currentConfig)) { |
| 252 | + $bookmarkConfig['views'][$bookmark->getIdentifier()]['data'] = $data[self::CURRENT_IDENTIFIER]; |
| 253 | + $bookmark->setConfig($this->serializer->serialize($bookmarkConfig)); |
| 254 | + $this->bookmarkRepository->save($bookmark); |
257 | 255 | }
|
258 | 256 | break;
|
259 | 257 | }
|
260 | 258 | }
|
261 | 259 | }
|
| 260 | + |
| 261 | + /** |
| 262 | + * Check if the positions for identical filters has changed |
| 263 | + * |
| 264 | + * @param array $existingConfig The existing configuration |
| 265 | + * @param array $currentConfig The current configuration |
| 266 | + * @return bool True if positions have changed, false otherwise |
| 267 | + */ |
| 268 | + private function isPositionChanged(array $existingConfig, array $currentConfig): bool |
| 269 | + { |
| 270 | + foreach (['filters', 'positions'] as $key) { |
| 271 | + if (!array_key_exists($key, $existingConfig) || !array_key_exists($key, $currentConfig)) { |
| 272 | + return false; |
| 273 | + } |
| 274 | + } |
| 275 | + |
| 276 | + return $existingConfig['filters'] === $currentConfig['filters'] |
| 277 | + && $existingConfig['positions'] !== $currentConfig['positions']; |
| 278 | + } |
262 | 279 | }
|
0 commit comments