Programmatically check the checkbox of an exposed filter I need to check a checkbox on an exposed filter for a view based on the url. I can't seem to figure out how to do that. If x is detected in the url, I want to set one of the fields of an exposed filter to have the status checked="checked." It seems like that would be pretty easy, but I can't seem to figure it out.

I have tried various ways through:


hook_views_pre_view()
hook_views_pre_build()
hook_form_views_exposed_form_alter() (I feel like this should be the best way.)


I've found that I can effectively alter the results through hook_views_pre_view(), but I can't figure out how to check that freaking checkbox on the exposed filter.

Varioush failed attempts via hook_form_alter():


$form["field_intended_use_target_id"]["#default_value"] = ['357'];
$form_state-&gt;input["field_intended_use_target_id"][356] = '356';
$form['field_intended_use_target_id']['widget'][0]['value']['#default_value'] = ['357'];


Can anyone please help?
I was finally able to achieve what I need via the hook_views_pre_build() hook. 

Please let me know if this is wrong or if there is a better way, but from what I can tell this is the best way to achieve this.

function module_views_pre_build(ViewExecutable $view) {
  $termId = 357;
  $view-&gt;setExposedInput(['field_name' =&gt; [$termId =&gt; $termId]]);
}