Open vincentrohde opened 5 years ago
You can do that in a event like:
$app->on('collections.find.after', function ($name, &$entries) use ($app) {
$ufields = ['_o', '_pid', '_by', '_mby', '_modified', '_created'];
foreach ($entries as $idx => $entry) {
foreach ($ufields as $ufield) {
if (array_key_exists($ufield, $entry)) {
unset($entries[$idx][$ufield]);
}
}
}
});
@pauloamgomes but only if it is an api request, otherwise this can break the backend ;-)
@pauloamgomes but only if it is an api request, otherwise this can break the backend ;-)
Yes, for sure, but is the only situation I think that (exclude some fields) can be required.
another option is
fields: {'_o':0, '_pid':0, '_by':0, '_mby':0, '_modified':0, '_created':0}
or adjust the fields property in the read rules (in the collection settings)
Thank you for all the responses!
fields: {'_o':0, '_pid':0, '_by':0, '_mby':0, '_modified':0, '_created':0}
Where do you implement this? If I put this into my fetch argument, the fields are not excluded from the API response. Am I missing something here?
or adjust the fields property in the read rules (in the collection settings)
Is there some documentation on editing the read rules?
I've run into this myself - collections.find.before
gives you &$options
, & collections.find.after
gives you &$entries
, but not the "other", which greatly limits what you can do with them :/
I feel like something is missing from somewhere - is it maybe possible to get the options from $app
somehow?
I don't think this is the best solution, but I've found using $_REQUEST
is valid in the events, so thats something in the meanwhile.
Heres the first iteration of a plugin I made to solve this problem: https://gist.github.com/G-Rath/934fabe5ed91fefe61d6f3e656527cd5
It's rough, but the basic idea is there - hopefully it'll be helpful to someone :)
Credit appreciated if used, as I'm interested in seeing what it actually gets used for 😉
When/if I get some time, I plan to try and make it into a proper plugin that hopefully has a frontend component.
Also, when you send: { "simple": true } There will be no fields-schema on top of the response.
Is there a way to exclude/ include certain things from the API response by declaring custom rules.
For example I would like to exclude all additional information from the CMS. These properties usually start with an . Is there a way to exclude all properties **starting with an or the field** property?
In the documentation, I can only find sparsely information about these two properties(filter and fields), in the JSON.stringify argument: