I have created a ViewsSort plugin that works on a normal view (like taxonomy_term) but not on a view based on Search API : it is not present when I click on “Add sort” in BO.
This sort is used to create a custom order of content types, and I use hook_views_data_alter() to provide it to views :
/**
* Implements hook_views_data_alter().
*/
function mymodule_views_data_alter(array &$data) {
// works on classic view
$data['node_field_data']['inspiration_first'] = array(
'title' => t('Custom search sort in page tags with inspiration first'),
'group' => t('Search'),
'help' => t('Sort content types in this order : dossier_inspiration, dossier_conseil, produit.'),
'sort' => array(
'field' => 'type',
'id' => 'inspiration_first',
),
);
// doesn't work on search api view
$data['search_api_db_default_search_content_index_content_type']['inspiration_first'] = array(
'title' => t('Place inspiration first for custom search'),
'group' => t('Search'),
'help' => t('Sort content types in this order : dossier_inspiration, dossier_conseil, produit.'),
'sort' => array(
'field' => 'value',
'id' => 'inspiration_first',
),
);
}
Any idea ? Some sorts like Random work also on search api and I’ve provided the good table, I think (search_api_db_default_search_content_index_content_type).