1

I have created a computed field, using ComputedFieldTrait. It is working fine, I am able to add the computed on the manage layout pages. I have implemented hook_views_data_alter() to tell Views about the computed field, and I am able to add the computed field to a view.

However, I need to do both a sort and a filter on the computed field.

My question: How do I structure my return value from hook_views_data_alter() so that views can use my computed field for sorting and filtering? Or is this even possible?

6
  • I think this was asked before and turned out to be not possible as the sorting happens in the DB query.
    – leymannx
    May 4, 2023 at 5:19
  • Yeah, I don't think it's possible. Hoping it is.
    – Jaypan
    May 4, 2023 at 14:22
  • Does this answer your question? How to sort View on rewritten field?
    – leymannx
    May 4, 2023 at 15:34
  • 2
    It turns out it's not possible. I came up with a workaround by creating custom views filter and sort plugins, that altered a column value in the query in the same manner I was altering the field value in the computed field. It works for my situation. But the answer to this question is that views cannot sort or filter on computed fields.
    – Jaypan
    May 4, 2023 at 23:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.