demos-europe / edt

Enables your PHP application to expose its entities as REST resources using the feature rich JSON:API specification as API. How and to whom your entities are exposed is highly customizable while minimizing boilerplate code.
MIT License
2 stars 1 forks source link

Add support for "functions" in Drupal filters #132

Open dresslerdemos opened 4 months ago

dresslerdemos commented 4 months ago

In some cases it may be helpful to define filters that do not rely directly on the value of a property, but that can adjust values before evaluating them.

Example 1: the API exposes article resources with a text attribute. That attribute value contains HTML. If you want to get all articles longer than some number of characters you need to strip the HTML tags from the text first. In pseudocode, it looks like this:

SIZE(STRIP_HTML(text)) >= 1000

Example 2: you want to know which users have written more than some number of characters overall by considering not only their articles but also comments. Unlike articles, comment texts do not contain HTML. To do so, you would need something like the following:

ADD(SIZE(STRIP_HTML(articles.text)), SIZE(comments.text)) >= 1000

How such function nesting can be integrated into the Drupal filter format best was not evaluated yet.

This seems to have a relationship to https://github.com/demos-europe/edt/issues/46