diff --git a/MediaGalleryUi/Model/SearchCriteria/CollectionProcessor/FilterProcessor/EntityId.php b/MediaGalleryUi/Model/SearchCriteria/CollectionProcessor/FilterProcessor/EntityId.php new file mode 100644 index 000000000000..3c105b559473 --- /dev/null +++ b/MediaGalleryUi/Model/SearchCriteria/CollectionProcessor/FilterProcessor/EntityId.php @@ -0,0 +1,63 @@ +connection = $resource; + } + /** + * @inheritDoc + */ + public function apply(Filter $filter, AbstractDb $collection): bool + { + $value = $filter->getValue(); + if (is_array($value)) { + $collection->addFieldToFilter( + self::TABLE_ALIAS . '.id', + ['in' => $this->getSelectByEntityType($value)] + ); + } + return true; + } + /** + * Return select asset ids by entity type + * + * @param array $value + * @return Select + */ + private function getSelectByEntityType(array $value): Select + { + return $this->connection->getConnection()->select()->from( + ['asset_content_table' => $this->connection->getTableName(self::MEDIA_CONTENT_ASSET_TABLE_NAME)], + ['asset_id'] + )->where( + 'entity_id IN (?)', + $value + )->where( + 'entity_type = "cms_page"' + ); + } +} diff --git a/MediaGalleryUi/Ui/Component/Listing/Filters/Options/Pages.php b/MediaGalleryUi/Ui/Component/Listing/Filters/Options/Pages.php new file mode 100644 index 000000000000..6fdca36b9e6d --- /dev/null +++ b/MediaGalleryUi/Ui/Component/Listing/Filters/Options/Pages.php @@ -0,0 +1,57 @@ +PageRepository = $pageRepository; + $this->SearchCriteriaBuilder = $searchCriteriaBuilder; + $this->FilterBuilder = $filterBuilder; + } + + /** + * @inheritdoc + */ + public function toOptionArray(): array + { + $searchCriteria = $this->SearchCriteriaBuilder->create(); + $pages = []; + $result = $this->PageRepository->getList($searchCriteria); + /** @var \Magento\Cms\Api\Data\PageInterface $page */ + foreach ($result->getItems() as $page) { + $pages[] = [ + 'value' => $page->getId(), + 'label' => $page->getTitle() + ]; + } + return $pages; + } +} diff --git a/MediaGalleryUi/etc/adminhtml/di.xml b/MediaGalleryUi/etc/adminhtml/di.xml index 0e1629c1e04c..9bd9dd370ad1 100644 --- a/MediaGalleryUi/etc/adminhtml/di.xml +++ b/MediaGalleryUi/etc/adminhtml/di.xml @@ -33,4 +33,11 @@ Magento\MediaGalleryUi\Model\Api\SearchCriteria\CollectionProcessor + + + + Magento\MediaGalleryUi\Model\SearchCriteria\CollectionProcessor\FilterProcessor\EntityId + + + diff --git a/MediaGalleryUi/view/adminhtml/ui_component/standalone_media_gallery_listing.xml b/MediaGalleryUi/view/adminhtml/ui_component/standalone_media_gallery_listing.xml index 0a08034354a2..150b7c097624 100644 --- a/MediaGalleryUi/view/adminhtml/ui_component/standalone_media_gallery_listing.xml +++ b/MediaGalleryUi/view/adminhtml/ui_component/standalone_media_gallery_listing.xml @@ -101,6 +101,23 @@ updated_at + + + + true + 1 + + + + + – Please Select a Page – + + page_id + + componentType = column, index = ${ $.index }:visible + + +