Filtering part of a multi-value field in a specific view I have an entity with fields that allow an unlimited number of values.

In a view, I would like to display a subset of those values that match a particular condition (eg. numbers less than n, dates in the past, etc.)

From investigation, it seems that a field formatter plugin is not a good way to solve this. Sure, I can extend DateTimeFormatterBase and override ::viewElements(FieldItemListInterface $items) to apply my condition, but at the price of being able to choose an actual field formatter. The custom plugin would have to take over the rendering too.

On the other hand, the Field plugin in views has some very limited options for limiting multiple values (by picking an offset and a count), but that doesn't seem extendable with a custom plugin.

Am I going to have to hook into the view after query execution to strip out the values that don't match the condition, or is there a cleaner way using the plugin API?

Edit: I suppose I could create a field formatter plugin that contains an option for selecting an actual formatter, and then passes the values that should be displayed on to it. This seems very roundabout, though. And this logic would have to be reimplemented for each field type!
In order to have full power over the filtering and sort order of the field inside each item, the best solution appears to be a sub-view using the views_field_view module.

https://drupal.org/project/views_field_view


Create a view that only shows the desired field (without a page display)
Add a contextual filter for the entity ID to be displayed
Add this to the parent view, setting the contextual filter to the entity ID of the current item.