Skip to content

Commit 91486f7

Browse files
committed
MediaGallery Used In filter fixes
1 parent 159f0c2 commit 91486f7

File tree

13 files changed

+527
-21
lines changed

13 files changed

+527
-21
lines changed
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\MediaContentApi\Api\GetContentByAssetIdsInterface;
16+
use Magento\Ui\Component\Filters\FilterModifier;
17+
use Magento\Ui\Component\Filters\Type\Select;
18+
use Magento\Ui\Api\BookmarkManagementInterface;
19+
use Magento\Cms\Api\BlockRepositoryInterface;
20+
21+
/**
22+
* Used in blocks filter
23+
*/
24+
class UsedInBlocks extends Select
25+
{
26+
/**
27+
* @var BookmarkManagementInterface
28+
*/
29+
private $bookmarkManagement;
30+
31+
/**
32+
* @var BlockRepositoryInterface
33+
*/
34+
private $blockRepository;
35+
36+
/**
37+
* @param ContextInterface $context
38+
* @param UiComponentFactory $uiComponentFactory
39+
* @param FilterBuilder $filterBuilder
40+
* @param FilterModifier $filterModifier
41+
* @param OptionSourceInterface $optionsProvider
42+
* @param BookmarkManagementInterface $bookmarkManagement
43+
* @param BlockRepositoryInterface $blockRepository
44+
* @param array $components
45+
* @param array $data
46+
*/
47+
public function __construct(
48+
ContextInterface $context,
49+
UiComponentFactory $uiComponentFactory,
50+
FilterBuilder $filterBuilder,
51+
FilterModifier $filterModifier,
52+
OptionSourceInterface $optionsProvider = null,
53+
BookmarkManagementInterface $bookmarkManagement,
54+
BlockRepositoryInterface $blockRepository,
55+
array $components = [],
56+
array $data = []
57+
) {
58+
$this->uiComponentFactory = $uiComponentFactory;
59+
$this->filterBuilder = $filterBuilder;
60+
parent::__construct(
61+
$context,
62+
$uiComponentFactory,
63+
$filterBuilder,
64+
$filterModifier,
65+
$optionsProvider,
66+
$components,
67+
$data
68+
);
69+
$this->bookmarkManagement = $bookmarkManagement;
70+
$this->blockRepository = $blockRepository;
71+
}
72+
73+
/*
74+
* Prepare component configuration
75+
*
76+
* @return void
77+
*/
78+
public function prepare()
79+
{
80+
$options = [];
81+
$blockIds = [];
82+
$bookmarks = $this->bookmarkManagement->loadByNamespace($this->context->getNameSpace())->getItems();
83+
foreach ($bookmarks as $bookmark) {
84+
if ($bookmark->getIdentifier() === 'current') {
85+
$applied = $bookmark->getConfig()['current']['filters']['applied'];
86+
if (isset($applied[$this->getName()])) {
87+
$blockIds = $applied[$this->getName()];
88+
}
89+
}
90+
}
91+
92+
foreach ($blockIds as $id) {
93+
$block = $this->blockRepository->getById($id);
94+
$options[] = [
95+
'value' => $id,
96+
'label' => $block->getTitle(),
97+
'is_active' => $block->isActive(),
98+
'optgroup' => false
99+
];
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+
}
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\MediaContentApi\Api\GetContentByAssetIdsInterface;
16+
use Magento\Ui\Component\Filters\FilterModifier;
17+
use Magento\Ui\Component\Filters\Type\Select;
18+
use Magento\Ui\Api\BookmarkManagementInterface;
19+
use Magento\Cms\Api\PageRepositoryInterface;
20+
21+
/**
22+
* Used in pages filter
23+
*/
24+
class UsedInPages extends Select
25+
{
26+
/**
27+
* @var BookmarkManagementInterface
28+
*/
29+
private $bookmarkManagement;
30+
31+
/**
32+
* @var PageRepositoryInterface
33+
*/
34+
private $pageRepository;
35+
36+
/**
37+
* @param ContextInterface $context
38+
* @param UiComponentFactory $uiComponentFactory
39+
* @param FilterBuilder $filterBuilder
40+
* @param FilterModifier $filterModifier
41+
* @param OptionSourceInterface $optionsProvider
42+
* @param BookmarkManagementInterface $bookmarkManagement
43+
* @param PageRepositoryInterface $pageRepository
44+
* @param array $components
45+
* @param array $data
46+
*/
47+
public function __construct(
48+
ContextInterface $context,
49+
UiComponentFactory $uiComponentFactory,
50+
FilterBuilder $filterBuilder,
51+
FilterModifier $filterModifier,
52+
OptionSourceInterface $optionsProvider = null,
53+
BookmarkManagementInterface $bookmarkManagement,
54+
PageRepositoryInterface $pageRepository,
55+
array $components = [],
56+
array $data = []
57+
) {
58+
$this->uiComponentFactory = $uiComponentFactory;
59+
$this->filterBuilder = $filterBuilder;
60+
parent::__construct(
61+
$context,
62+
$uiComponentFactory,
63+
$filterBuilder,
64+
$filterModifier,
65+
$optionsProvider,
66+
$components,
67+
$data
68+
);
69+
$this->bookmarkManagement = $bookmarkManagement;
70+
$this->pageRepository = $pageRepository;
71+
}
72+
73+
/*
74+
* Prepare component configuration
75+
*
76+
* @return void
77+
*/
78+
public function prepare()
79+
{
80+
$options = [];
81+
$pageIds = [];
82+
$bookmarks = $this->bookmarkManagement->loadByNamespace($this->context->getNameSpace())->getItems();
83+
foreach ($bookmarks as $bookmark) {
84+
if ($bookmark->getIdentifier() === 'current') {
85+
$applied = $bookmark->getConfig()['current']['filters']['applied'];
86+
if (isset($applied[$this->getName()])) {
87+
$pageIds = $applied[$this->getName()];
88+
}
89+
}
90+
}
91+
92+
foreach ($pageIds as $id) {
93+
$page = $this->pageRepository->getById($id);
94+
$options[] = [
95+
'value' => $id,
96+
'label' => $page->getTitle(),
97+
'is_active' => $page->isActive(),
98+
'optgroup' => false
99+
];
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+
}
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\MediaContentApi\Api\GetContentByAssetIdsInterface;
16+
use Magento\Ui\Component\Filters\FilterModifier;
17+
use Magento\Ui\Component\Filters\Type\Select;
18+
use Magento\Ui\Api\BookmarkManagementInterface;
19+
use Magento\Catalog\Api\ProductRepositoryInterface;
20+
21+
/**
22+
* Used in products filter
23+
*/
24+
class UsedInProducts extends Select
25+
{
26+
/**
27+
* @var BookmarkManagementInterface
28+
*/
29+
private $bookmarkManagement;
30+
31+
/**
32+
* @var ProductRepositoryInterface
33+
*/
34+
private $productRepository;
35+
36+
/**
37+
* @param ContextInterface $context
38+
* @param UiComponentFactory $uiComponentFactory
39+
* @param FilterBuilder $filterBuilder
40+
* @param FilterModifier $filterModifier
41+
* @param OptionSourceInterface $optionsProvider
42+
* @param BookmarkManagementInterface $bookmarkManagement
43+
* @param ProductRepositoryInterface $productRepository
44+
* @param array $components
45+
* @param array $data
46+
*/
47+
public function __construct(
48+
ContextInterface $context,
49+
UiComponentFactory $uiComponentFactory,
50+
FilterBuilder $filterBuilder,
51+
FilterModifier $filterModifier,
52+
OptionSourceInterface $optionsProvider = null,
53+
BookmarkManagementInterface $bookmarkManagement,
54+
ProductRepositoryInterface $productRepository,
55+
array $components = [],
56+
array $data = []
57+
) {
58+
$this->uiComponentFactory = $uiComponentFactory;
59+
$this->filterBuilder = $filterBuilder;
60+
parent::__construct(
61+
$context,
62+
$uiComponentFactory,
63+
$filterBuilder,
64+
$filterModifier,
65+
$optionsProvider,
66+
$components,
67+
$data
68+
);
69+
$this->bookmarkManagement = $bookmarkManagement;
70+
$this->productRepository = $productRepository;
71+
}
72+
73+
/*
74+
* Prepare component configuration
75+
*
76+
* @return void
77+
*/
78+
public function prepare()
79+
{
80+
$options = [];
81+
$productIds = [];
82+
$bookmarks = $this->bookmarkManagement->loadByNamespace($this->context->getNameSpace())->getItems();
83+
foreach ($bookmarks as $bookmark) {
84+
if ($bookmark->getIdentifier() === 'current') {
85+
$applied = $bookmark->getConfig()['current']['filters']['applied'];
86+
if (isset($applied[$this->getName()])) {
87+
$productIds = $applied[$this->getName()];
88+
}
89+
}
90+
}
91+
92+
foreach ($productIds as $id) {
93+
$product = $this->productRepository->getById($id);
94+
$options[] = [
95+
'value' => $id,
96+
'label' => $product->getName(),
97+
'is_active' => $product->getStatus(),
98+
'path' => $product->getSku(),
99+
'optgroup' => false
100+
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+
$jsConfig = array_replace_recursive(
116+
$this->getJsConfig($this->wrappedComponent),
117+
$this->getJsConfig($this)
118+
);
119+
$this->setData('js_config', $jsConfig);
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+
}

0 commit comments

Comments
 (0)