In a view, I want to sort content by:
- Collection (a taxonomy term)
- Content type
- Something else
- Something else …
I have this configured in the View UI and I want to leave most of it as it is but for the content type ordering, I want to make this literal – I want to state the order exactly (“article”, “page”, “thingy”, “other one”).
For this in MySQL you would use FIELD()
I have tried using hook_views_query_alter
and setting $query->orderby[1][field]
to FIELD(node_field_data_type, "article", "page", "thingy", "other one")
but I am running into exactly this problem: https://www.drupal.org/node/1382016#comment-12058755 In other words, the brackets and quotes are being removed so that it thinks it’s one long field name (which of course does not exist) rather than treating it as a function call. It seems this did not happen in Drupal 7.
Is there a known way to get around this in Drupal 8?