Skip to content

Commit 957f37e

Browse files
authored
ENGCOM-7976: Fix urlFilterApplier for filter values as array #29367
2 parents 1acc523 + a281901 commit 957f37e

File tree

15 files changed

+452
-31
lines changed

15 files changed

+452
-31
lines changed
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\MediaGalleryCatalogUi\Ui\Component\Listing\Filters;
10+
11+
use Magento\Framework\Api\FilterBuilder;
12+
use Magento\Framework\Data\OptionSourceInterface;
13+
use Magento\Framework\View\Element\UiComponent\ContextInterface;
14+
use Magento\Framework\View\Element\UiComponentFactory;
15+
use Magento\Ui\Component\Filters\FilterModifier;
16+
use Magento\Ui\Component\Filters\Type\Select;
17+
use Magento\Ui\Api\BookmarkManagementInterface;
18+
use Magento\Catalog\Api\ProductRepositoryInterface;
19+
20+
/**
21+
* Used in products filter
22+
*/
23+
class UsedInProducts extends Select
24+
{
25+
/**
26+
* @var BookmarkManagementInterface
27+
*/
28+
private $bookmarkManagement;
29+
30+
/**
31+
* @var ProductRepositoryInterface
32+
*/
33+
private $productRepository;
34+
35+
/**
36+
* Constructor
37+
*
38+
* @param ContextInterface $context
39+
* @param UiComponentFactory $uiComponentFactory
40+
* @param FilterBuilder $filterBuilder
41+
* @param FilterModifier $filterModifier
42+
* @param OptionSourceInterface $optionsProvider
43+
* @param BookmarkManagementInterface $bookmarkManagement
44+
* @param ProductRepositoryInterface $productRepository
45+
* @param array $components
46+
* @param array $data
47+
*/
48+
public function __construct(
49+
ContextInterface $context,
50+
UiComponentFactory $uiComponentFactory,
51+
FilterBuilder $filterBuilder,
52+
FilterModifier $filterModifier,
53+
OptionSourceInterface $optionsProvider = null,
54+
BookmarkManagementInterface $bookmarkManagement,
55+
ProductRepositoryInterface $productRepository,
56+
array $components = [],
57+
array $data = []
58+
) {
59+
$this->uiComponentFactory = $uiComponentFactory;
60+
$this->filterBuilder = $filterBuilder;
61+
parent::__construct(
62+
$context,
63+
$uiComponentFactory,
64+
$filterBuilder,
65+
$filterModifier,
66+
$optionsProvider,
67+
$components,
68+
$data
69+
);
70+
$this->bookmarkManagement = $bookmarkManagement;
71+
$this->productRepository = $productRepository;
72+
}
73+
74+
/**
75+
* Prepare component configuration
76+
*
77+
* @return void
78+
*/
79+
public function prepare()
80+
{
81+
$options = [];
82+
$productIds = [];
83+
$bookmarks = $this->bookmarkManagement->loadByNamespace($this->context->getNameSpace())->getItems();
84+
foreach ($bookmarks as $bookmark) {
85+
if ($bookmark->getIdentifier() === 'current') {
86+
$applied = $bookmark->getConfig()['current']['filters']['applied'];
87+
if (isset($applied[$this->getName()])) {
88+
$productIds = $applied[$this->getName()];
89+
}
90+
}
91+
}
92+
93+
foreach ($productIds as $id) {
94+
$product = $this->productRepository->getById($id);
95+
$options[] = [
96+
'value' => $id,
97+
'label' => $product->getName(),
98+
'is_active' => $product->getStatus(),
99+
'path' => $product->getSku(),
100+
'optgroup' => false
101+
102+
];
103+
}
104+
105+
$this->wrappedComponent = $this->uiComponentFactory->create(
106+
$this->getName(),
107+
parent::COMPONENT,
108+
[
109+
'context' => $this->getContext(),
110+
'options' => $options
111+
]
112+
);
113+
114+
$this->wrappedComponent->prepare();
115+
$productsFilterJsConfig = array_replace_recursive(
116+
$this->getJsConfig($this->wrappedComponent),
117+
$this->getJsConfig($this)
118+
);
119+
$this->setData('js_config', $productsFilterJsConfig);
120+
121+
$this->setData(
122+
'config',
123+
array_replace_recursive(
124+
(array)$this->wrappedComponent->getData('config'),
125+
(array)$this->getData('config')
126+
)
127+
);
128+
129+
$this->applyFilter();
130+
131+
parent::prepare();
132+
}
133+
}

app/code/Magento/MediaGalleryCatalogUi/view/adminhtml/ui_component/media_gallery_listing.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
name="product_id"
1414
provider="${ $.parentName }"
1515
sortOrder="110"
16+
class="Magento\MediaGalleryCatalogUi\Ui\Component\Listing\Filters\UsedInProducts"
1617
component="Magento_Catalog/js/components/product-ui-select"
1718
template="ui/grid/filters/elements/ui-select">
1819
<argument name="data" xsi:type="array">

app/code/Magento/MediaGalleryCatalogUi/view/adminhtml/ui_component/standalone_media_gallery_listing.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
name="product_id"
1414
provider="${ $.parentName }"
1515
sortOrder="110"
16+
class="Magento\MediaGalleryCatalogUi\Ui\Component\Listing\Filters\UsedInProducts"
1617
component="Magento_Catalog/js/components/product-ui-select"
1718
template="ui/grid/filters/elements/ui-select">
1819
<argument name="data" xsi:type="array">
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\MediaGalleryCmsUi\Ui\Component\Listing\Filters;
10+
11+
use Magento\Framework\Api\FilterBuilder;
12+
use Magento\Framework\Data\OptionSourceInterface;
13+
use Magento\Framework\View\Element\UiComponent\ContextInterface;
14+
use Magento\Framework\View\Element\UiComponentFactory;
15+
use Magento\Ui\Component\Filters\FilterModifier;
16+
use Magento\Ui\Component\Filters\Type\Select;
17+
use Magento\Ui\Api\BookmarkManagementInterface;
18+
use Magento\Cms\Api\BlockRepositoryInterface;
19+
20+
/**
21+
* Used in blocks filter
22+
*/
23+
class UsedInBlocks extends Select
24+
{
25+
/**
26+
* @var BookmarkManagementInterface
27+
*/
28+
private $bookmarkManagement;
29+
30+
/**
31+
* @var BlockRepositoryInterface
32+
*/
33+
private $blockRepository;
34+
35+
/**
36+
* Constructor
37+
*
38+
* @param ContextInterface $context
39+
* @param UiComponentFactory $uiComponentFactory
40+
* @param FilterBuilder $filterBuilder
41+
* @param FilterModifier $filterModifier
42+
* @param OptionSourceInterface $optionsProvider
43+
* @param BookmarkManagementInterface $bookmarkManagement
44+
* @param BlockRepositoryInterface $blockRepository
45+
* @param array $components
46+
* @param array $data
47+
*/
48+
public function __construct(
49+
ContextInterface $context,
50+
UiComponentFactory $uiComponentFactory,
51+
FilterBuilder $filterBuilder,
52+
FilterModifier $filterModifier,
53+
OptionSourceInterface $optionsProvider = null,
54+
BookmarkManagementInterface $bookmarkManagement,
55+
BlockRepositoryInterface $blockRepository,
56+
array $components = [],
57+
array $data = []
58+
) {
59+
$this->uiComponentFactory = $uiComponentFactory;
60+
$this->filterBuilder = $filterBuilder;
61+
parent::__construct(
62+
$context,
63+
$uiComponentFactory,
64+
$filterBuilder,
65+
$filterModifier,
66+
$optionsProvider,
67+
$components,
68+
$data
69+
);
70+
$this->bookmarkManagement = $bookmarkManagement;
71+
$this->blockRepository = $blockRepository;
72+
}
73+
74+
/**
75+
* Prepare component configuration
76+
*
77+
* @return void
78+
*/
79+
public function prepare()
80+
{
81+
$options = [];
82+
$blockIds = [];
83+
$bookmarks = $this->bookmarkManagement->loadByNamespace($this->context->getNameSpace())->getItems();
84+
foreach ($bookmarks as $bookmark) {
85+
if ($bookmark->getIdentifier() === 'current') {
86+
$applied = $bookmark->getConfig()['current']['filters']['applied'];
87+
if (isset($applied[$this->getName()])) {
88+
$blockIds = $applied[$this->getName()];
89+
}
90+
}
91+
}
92+
93+
foreach ($blockIds as $id) {
94+
$block = $this->blockRepository->getById($id);
95+
$options[] = [
96+
'value' => $id,
97+
'label' => $block->getTitle(),
98+
'is_active' => $block->isActive(),
99+
'optgroup' => false
100+
];
101+
}
102+
103+
$this->wrappedComponent = $this->uiComponentFactory->create(
104+
$this->getName(),
105+
parent::COMPONENT,
106+
[
107+
'context' => $this->getContext(),
108+
'options' => $options
109+
]
110+
);
111+
112+
$this->wrappedComponent->prepare();
113+
$jsConfig = array_replace_recursive(
114+
$this->getJsConfig($this->wrappedComponent),
115+
$this->getJsConfig($this)
116+
);
117+
$this->setData('js_config', $jsConfig);
118+
119+
$this->setData(
120+
'config',
121+
array_replace_recursive(
122+
(array)$this->wrappedComponent->getData('config'),
123+
(array)$this->getData('config')
124+
)
125+
);
126+
127+
$this->applyFilter();
128+
129+
parent::prepare();
130+
}
131+
}

0 commit comments

Comments
 (0)