diff --git a/src/grid/RepresentationCollectionFinder.php b/src/grid/RepresentationCollectionFinder.php index 3a12acb6..0cb5f5e6 100644 --- a/src/grid/RepresentationCollectionFinder.php +++ b/src/grid/RepresentationCollectionFinder.php @@ -22,7 +22,7 @@ * * @author Dmytro Naumenko */ -class RepresentationCollectionFinder +class RepresentationCollectionFinder implements RepresentationCollectionFinderInterface { private $module; private $controller; @@ -86,10 +86,14 @@ public function findOrFail() return $collection; } - public static function forCurrentRoute(string $representationsLocation) + public static function forCurrentRoute(string $representationsLocation): RepresentationCollectionFinderInterface { $controller = Yii::$app->controller; + if ($controller->module instanceof RepresentationCollectionFinderProviderInterface) { + return $controller->module->getRepresentationCollectionFinder(); + } + $module = $controller->module->id; $controller = Inflector::id2camel($controller->id); diff --git a/src/grid/RepresentationCollectionFinderInterface.php b/src/grid/RepresentationCollectionFinderInterface.php new file mode 100644 index 00000000..dac2a9e5 --- /dev/null +++ b/src/grid/RepresentationCollectionFinderInterface.php @@ -0,0 +1,32 @@ + + */ +interface RepresentationCollectionFinderInterface +{ + /** + * @return RepresentationCollectionInterface|RepresentationCollection + */ + public function find(); + + /** + * @throws InvalidConfigException When collection does not exist for the route + * @return RepresentationCollection|RepresentationCollectionInterface + */ + public function findOrFail(); + + /** + * @return RepresentationCollectionInterface|RepresentationCollection + */ + public function findOrFallback(); +} diff --git a/src/grid/RepresentationCollectionFinderProviderInterface.php b/src/grid/RepresentationCollectionFinderProviderInterface.php new file mode 100644 index 00000000..fecdab75 --- /dev/null +++ b/src/grid/RepresentationCollectionFinderProviderInterface.php @@ -0,0 +1,8 @@ +