Skip to content

Commit 7db7c5e

Browse files
Indrani SonawaneIndrani Sonawane
authored andcommitted
Merge remote-tracking branch '38996/patch-24' into comprs_v2
2 parents bb3efa8 + 6d05450 commit 7db7c5e

File tree

1 file changed

+25
-8
lines changed
  • app/code/Magento/Ui/Controller/Adminhtml/Bookmark

1 file changed

+25
-8
lines changed

app/code/Magento/Ui/Controller/Adminhtml/Bookmark/Save.php

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Ui\Controller\Adminhtml\Bookmark;
79

810
use Magento\Authorization\Model\UserContextInterface;
@@ -246,17 +248,32 @@ private function updateCurrentBookmarkConfig(array $data): void
246248
$bookmarkConfig = $bookmark->getConfig();
247249
$existingConfig = $bookmarkConfig['views'][$bookmark->getIdentifier()]['data'] ?? null;
248250
$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);
257255
}
258256
break;
259257
}
260258
}
261259
}
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+
}
262279
}

0 commit comments

Comments
 (0)