1616use Pimcore \Bundle \StudioBackendBundle \Asset \Schema \Type \AssetFolder ;
1717use Pimcore \Bundle \StudioBackendBundle \DataIndex \AssetSearchResult ;
1818use Pimcore \Bundle \StudioBackendBundle \DataIndex \DataObjectSearchResult ;
19+ use Pimcore \Bundle \StudioBackendBundle \DataIndex \DocumentSearchResult ;
1920use Pimcore \Bundle \StudioBackendBundle \DataIndex \Query \AssetQueryInterface ;
2021use Pimcore \Bundle \StudioBackendBundle \DataIndex \Query \DataObjectQueryInterface ;
22+ use Pimcore \Bundle \StudioBackendBundle \DataIndex \Query \DocumentQueryInterface ;
2123use Pimcore \Bundle \StudioBackendBundle \DataIndex \SearchIndexFilterInterface ;
2224use Pimcore \Bundle \StudioBackendBundle \DataIndex \Service \AssetSearchServiceInterface ;
2325use Pimcore \Bundle \StudioBackendBundle \DataIndex \Service \DataObjectSearchServiceInterface ;
26+ use Pimcore \Bundle \StudioBackendBundle \DataIndex \Service \DocumentSearchServiceInterface ;
2427use Pimcore \Bundle \StudioBackendBundle \DataObject \Schema \Type \DataObjectFolder ;
2528use Pimcore \Bundle \StudioBackendBundle \Exception \Api \InvalidArgumentException ;
2629use Pimcore \Bundle \StudioBackendBundle \Exception \Api \InvalidElementTypeException ;
@@ -44,6 +47,7 @@ public function __construct(
4447 private FilterServiceProviderInterface $ filterServiceProvider ,
4548 private AssetSearchServiceInterface $ assetSearchService ,
4649 private DataObjectSearchServiceInterface $ dataObjectSearchService ,
50+ private DocumentSearchServiceInterface $ documentSearchService ,
4751 private SecurityServiceInterface $ securityService
4852 ) {
4953 $ this ->filterService = $ this ->filterServiceProvider ->create (SearchIndexFilterInterface::SERVICE_TYPE );
@@ -79,11 +83,20 @@ public function searchDataObjects(GridParameter $gridParameter): DataObjectSearc
7983 );
8084 }
8185
86+ public function searchDocuments (GridParameter $ gridParameter ): DocumentSearchResult
87+ {
88+ return $ this ->searchElementsForUser (
89+ ElementTypes::TYPE_DOCUMENT ,
90+ $ gridParameter ,
91+ $ this ->securityService ->getCurrentUser ()
92+ );
93+ }
94+
8295 public function searchElementsForUser (
8396 string $ type ,
8497 GridParameter $ gridParameter ,
8598 UserInterface $ user
86- ): AssetSearchResult |DataObjectSearchResult {
99+ ): AssetSearchResult |DataObjectSearchResult | DocumentSearchResult {
87100 $ filter = $ gridParameter ->getFilters ();
88101 $ type = $ this ->getStudioElementType ($ type );
89102
@@ -96,6 +109,10 @@ public function searchElementsForUser(
96109 $ gridParameter ->getFolderId (),
97110 $ user
98111 ),
112+ ElementTypes::TYPE_DOCUMENT => $ this ->documentSearchService ->getDocumentById (
113+ $ gridParameter ->getFolderId (),
114+ $ user
115+ ),
99116 default => throw new InvalidElementTypeException ($ type )
100117 };
101118
@@ -105,7 +122,7 @@ public function searchElementsForUser(
105122
106123 $ filter ->setPath ($ folder ->getFullPath ());
107124
108- /** @var AssetQueryInterface|DataObjectQueryInterface $query */
125+ /** @var AssetQueryInterface|DataObjectQueryInterface|DocumentQueryInterface $query */
109126 $ query = $ this ->filterService ->applyFilters (
110127 $ filter ,
111128 $ type
@@ -116,6 +133,7 @@ public function searchElementsForUser(
116133 return match ($ type ) {
117134 ElementTypes::TYPE_ASSET => $ this ->assetSearchService ->searchAssets ($ query ),
118135 ElementTypes::TYPE_DATA_OBJECT => $ this ->dataObjectSearchService ->searchDataObjects ($ query ),
136+ ElementTypes::TYPE_DOCUMENT => $ this ->documentSearchService ->searchDocuments ($ query ),
119137 default => throw new InvalidElementTypeException ($ type )
120138 };
121139 }
@@ -130,6 +148,11 @@ private function isFolderOfType(string $type, StudioElementInterface $element):
130148 return true ;
131149 }
132150
151+ // Allow all documents as folder sinc they can all have parent items.
152+ if ($ type === ElementTypes::TYPE_DOCUMENT ) {
153+ return true ;
154+ }
155+
133156 return false ;
134157 }
135158
0 commit comments