diff --git a/config/data_index_filters.yaml b/config/data_index_filters.yaml index f5d2445e1..6879e0e19 100644 --- a/config/data_index_filters.yaml +++ b/config/data_index_filters.yaml @@ -41,6 +41,9 @@ services: Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\UserFilter: tags: [ 'pimcore.studio_backend.open_search.filter' ] + Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\IdFilter: + tags: [ 'pimcore.studio_backend.open_search.filter' ] + Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\IntegerFilter: tags: [ 'pimcore.studio_backend.open_search.filter' ] diff --git a/config/grid.yaml b/config/grid.yaml index 3bfe3a57a..dc872da3a 100644 --- a/config/grid.yaml +++ b/config/grid.yaml @@ -75,6 +75,9 @@ services: Pimcore\Bundle\StudioBackendBundle\Grid\Column\Definition\System\IntegerDefinition: tags: [ 'pimcore.studio_backend.grid_column_definition' ] + Pimcore\Bundle\StudioBackendBundle\Grid\Column\Definition\System\IdDefinition: + tags: [ 'pimcore.studio_backend.grid_column_definition' ] + Pimcore\Bundle\StudioBackendBundle\Grid\Column\Definition\System\StringDefinition: tags: [ 'pimcore.studio_backend.grid_column_definition' ] diff --git a/doc/03_Grid.md b/doc/03_Grid.md index 5f35bffe6..1ceb4b613 100644 --- a/doc/03_Grid.md +++ b/doc/03_Grid.md @@ -43,6 +43,7 @@ Available filters are: | system.datetime | integer | `from`, `to`, or `on` | true | | system.tag | object | `considerChildTags`, `tags` | false | | system.pql | string | PQL Query | false | +| system.id | integer | | false | | system.integer | string | | true | diff --git a/src/DataIndex/Filter/IdFilter.php b/src/DataIndex/Filter/IdFilter.php new file mode 100644 index 000000000..15247aaf3 --- /dev/null +++ b/src/DataIndex/Filter/IdFilter.php @@ -0,0 +1,50 @@ +getSimpleColumnFilterByType(ColumnType::SYSTEM_ID->value); + + if (!$filter) { + return $query; + } + + if (!is_int($filter->getFilterValue())) { + throw new InvalidArgumentException('Filter value for this filter must be a integer'); + } + + $query->searchByIds([$filter->getFilterValue()]); + + return $query; + } +} diff --git a/src/Grid/Column/ColumnType.php b/src/Grid/Column/ColumnType.php index 78bbd53ec..fec5ee0ab 100644 --- a/src/Grid/Column/ColumnType.php +++ b/src/Grid/Column/ColumnType.php @@ -24,6 +24,7 @@ enum ColumnType: string case SYSTEM_STRING = 'system.string'; case SYSTEM_FILE_SIZE = 'system.fileSize'; case SYSTEM_INTEGER = 'system.integer'; + case SYSTEM_ID = 'system.id'; case SYSTEM_DATETIME = 'system.datetime'; case SYSTEM_TAG = 'system.tag'; case SYSTEM_PQL_QUERY = 'system.pql'; diff --git a/src/Grid/Column/Definition/System/IdDefinition.php b/src/Grid/Column/Definition/System/IdDefinition.php new file mode 100644 index 000000000..fe7c08aa5 --- /dev/null +++ b/src/Grid/Column/Definition/System/IdDefinition.php @@ -0,0 +1,52 @@ +value; + } + + public function getConfig(mixed $config): array + { + return []; + } + + public function isSortable(): bool + { + return true; + } + + public function getFrontendType(): string + { + return FrontendType::INPUT->value; + } + + public function isExportable(): bool + { + return true; + } +} diff --git a/src/Grid/Mapper/ColumnMapper.php b/src/Grid/Mapper/ColumnMapper.php index b2009f9ff..540512777 100644 --- a/src/Grid/Mapper/ColumnMapper.php +++ b/src/Grid/Mapper/ColumnMapper.php @@ -27,7 +27,7 @@ { private const COLUMN_MAPPING = [ 'preview' => 'image', - 'id' => 'integer', + 'id' => 'id', 'type' => 'string', 'fullpath' => 'string', 'filename' => 'string', diff --git a/tests/Unit/Grid/Mapper/ColumnMapperTest.php b/tests/Unit/Grid/Mapper/ColumnMapperTest.php index f5f88cfac..ba419db0a 100644 --- a/tests/Unit/Grid/Mapper/ColumnMapperTest.php +++ b/tests/Unit/Grid/Mapper/ColumnMapperTest.php @@ -43,7 +43,7 @@ public function testMapperForPreview(): void public function testMapperForId(): void { $mapper = new ColumnMapper(); - $this->assertSame('integer', $mapper->getType('id')); + $this->assertSame('id', $mapper->getType('id')); } public function testMapperForType(): void diff --git a/tests/Unit/Grid/Service/SystemColumnServiceTest.php b/tests/Unit/Grid/Service/SystemColumnServiceTest.php index a4c7a41ec..86e934391 100644 --- a/tests/Unit/Grid/Service/SystemColumnServiceTest.php +++ b/tests/Unit/Grid/Service/SystemColumnServiceTest.php @@ -32,7 +32,7 @@ public function testGetSystemColumnsForAssets(): void $this->assertSame([ 'preview' => 'image', - 'id' => 'integer', + 'id' => 'id', 'type' => 'string', 'fullpath' => 'string', 'filename' => 'string', @@ -48,7 +48,7 @@ public function testGetSystemColumnsForDataObjects(): void $systemColumnService = new SystemColumnService($mapper); $this->assertSame([ - 'id' => 'integer', + 'id' => 'id', 'fullpath' => 'string', 'key' => 'string', 'published' => 'boolean',