0
votes

I added a Language custom field ( a taxonomy term ) to my user entity and another entity (Activity).

This field can have 2 values, English and French. (User can have both, activity can only have one)

On the Activities view, i added an exposed filter (select) so the user can filter French or English activities.

enter image description here

Result :

enter image description here

I want to hide (or disable) this select if the user only has 1 Language.

How to properly achieve this ? i tried the pre_render hooks but i can't find the right one i guess.

Thank you.

1
Please show your current code to show the select and how you retrieve the language list for the user. Based on this info, we can help - Andrea Olivato
Hi, i didn't do this with code, i used the views interface. I edited my answer with the screenshot of the filter i added. - Mohamed Amine Bouhadjar

1 Answers

4
votes

you should try this hook:

function themename_form_alter(&$form, FormStateInterface $form_state, $form_id) {
    if (in_array($form_id, ['views_exposed_form'])) {
        if ($form['#id'] == "views-exposed-form-custom-search-page-1") {  // your form id
            // your filter logic and return filter form value like
            // $form["langugae"]["#options"] = $options;
        }
    }
}