diff --git a/MediaGalleryUi/Model/SearchCriteria/CollectionProcessor/FilterProcessor/EntityType.php b/MediaGalleryUi/Model/SearchCriteria/CollectionProcessor/FilterProcessor/EntityType.php
index 925b486439c9..67d854e45273 100644
--- a/MediaGalleryUi/Model/SearchCriteria/CollectionProcessor/FilterProcessor/EntityType.php
+++ b/MediaGalleryUi/Model/SearchCriteria/CollectionProcessor/FilterProcessor/EntityType.php
@@ -20,6 +20,8 @@ class EntityType implements CustomFilterInterface
{
private const TABLE_ALIAS = 'main_table';
private const TABLE_MEDIA_CONTENT_ASSET = 'media_content_asset';
+ private const TABLE_MEDIA_GALLERY_ASSET = 'media_gallery_asset';
+ private const NOT_USED = 'not_used';
/**
* @var ResourceConnection
@@ -41,9 +43,20 @@ public function apply(Filter $filter, AbstractDb $collection): bool
{
$value = $filter->getValue();
if (is_array($value)) {
+ $conditions = [];
+
+ if (in_array(self::NOT_USED, $value)) {
+ unset($value[array_search(self::NOT_USED, $value)]);
+ $conditions[] = ['in' => $this->getNotUsedEntityIds()];
+ }
+
+ if (!empty($value)) {
+ $conditions[] = ['in' => $this->getSelectByEntityType($value)];
+ }
+
$collection->addFieldToFilter(
self::TABLE_ALIAS . '.id',
- ['in' => $this->getSelectByEntityType($value)]
+ $conditions
);
}
return true;
@@ -65,4 +78,21 @@ private function getSelectByEntityType(array $value): Select
$value
);
}
+
+ /**
+ * Return select asset ids that not exists in asset_content_table
+ */
+ private function getNotUsedEntityIds(): Select
+ {
+ return $this->connection->getConnection()->select()->from(
+ ['media_gallery_asset' => $this->connection->getTableName(self::TABLE_MEDIA_GALLERY_ASSET)],
+ ['id']
+ )->where(
+ 'media_gallery_asset.id not in ?',
+ $this->connection->getConnection()->select()->from(
+ ['asset_content_table' => $this->connection->getTableName(self::TABLE_MEDIA_CONTENT_ASSET)],
+ ['asset_id']
+ )
+ );
+ }
}
diff --git a/MediaGalleryUi/Test/Mftf/Test/AdminEnhancedMediaGalleryVerifyNotUsedOptionFilterTest.xml b/MediaGalleryUi/Test/Mftf/Test/AdminEnhancedMediaGalleryVerifyNotUsedOptionFilterTest.xml
new file mode 100644
index 000000000000..e22eedf8923f
--- /dev/null
+++ b/MediaGalleryUi/Test/Mftf/Test/AdminEnhancedMediaGalleryVerifyNotUsedOptionFilterTest.xml
@@ -0,0 +1,75 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/MediaGalleryUi/etc/adminhtml/di.xml b/MediaGalleryUi/etc/adminhtml/di.xml
index 434674ff8c9b..bf07512d13d4 100644
--- a/MediaGalleryUi/etc/adminhtml/di.xml
+++ b/MediaGalleryUi/etc/adminhtml/di.xml
@@ -60,6 +60,10 @@
- catalog_product
- Products
+ -
+
- not_used
+ - Not used anywhere
+