craftcms / element-api

Create a JSON API/Feed for your elements in Craft.
MIT License
498 stars 57 forks source link

Allow defaults setting to be set to a closure #98

Closed carlcs closed 5 years ago

carlcs commented 5 years ago

When defining defaults I need to make use of Craft’s request service, and without having it in a callable it’s throwing errors on console requests.

return [
    'defaults' => function() {
        $request = Craft::$app->getRequest();
        return [
            'paginate' => false,
            'includes' => (array)$request->getQueryParam('include'),
            'excludes' => (array)$request->getQueryParam('exclude'),
        ];
    },
    'endpoints' => [],
];
brandonkelly commented 5 years ago

Good idea, thanks!

brandonkelly commented 5 years ago

Element API 2.6.0 is out now with this change.