Skip to main content
Add sample code.
Source Link
Jigarius
  • 3.1k
  • 16
  • 21

I can see two possible solutions to this problem:

Solution 1: Better Exposed Filters

Install the Better Exposed Filters module. There are over 31,227 sites using it at the moment. Don't let the fact that it is in alpha hold you back unless your organization has a policy preventing you from using alpha releases.

Solution 2: Custom Code

If you cannot use Better Exposed Filters for some reason, then write a hook_form_FORM_ID_alter() to modify your views exposed form the way you want.

Sample code

Create a hook_form_FORM_ID_alter() in a custom module. In the example below, the module name is custom_general.

/** * Implements hook_form_FORM_ID_alter(). */ function custom_general_form_views_exposed_form_alter( &$form, FormStateInterface $form_state, $form_id ) { $view_data = $form_state->getStorage('view'); // Content administration. if ($view_data['view']->id() === 'VIEW-ID') { // Analyze the structure of your form with kint(). // Say, the field that matters to you is "field_foobar". // kint($form); exit; if (isset($form['field_foobar']) { $form['field_foobar']['#type'] = 'select'; $form['field_foobar']['#multiple'] = FALSE; $form['field_foobar']['#size'] = 1; // TODO: Do other things as necessary. } } } 

I can see two possible solutions to this problem:

Solution 1: Better Exposed Filters

Install the Better Exposed Filters module. There are over 31,227 sites using it at the moment. Don't let the fact that it is in alpha hold you back unless your organization has a policy preventing you from using alpha releases.

Solution 2: Custom Code

If you cannot use Better Exposed Filters for some reason, then write a hook_form_FORM_ID_alter() to modify your views exposed form the way you want.

I can see two possible solutions to this problem:

Solution 1: Better Exposed Filters

Install the Better Exposed Filters module. There are over 31,227 sites using it at the moment. Don't let the fact that it is in alpha hold you back unless your organization has a policy preventing you from using alpha releases.

Solution 2: Custom Code

If you cannot use Better Exposed Filters for some reason, then write a hook_form_FORM_ID_alter() to modify your views exposed form the way you want.

Sample code

Create a hook_form_FORM_ID_alter() in a custom module. In the example below, the module name is custom_general.

/** * Implements hook_form_FORM_ID_alter(). */ function custom_general_form_views_exposed_form_alter( &$form, FormStateInterface $form_state, $form_id ) { $view_data = $form_state->getStorage('view'); // Content administration. if ($view_data['view']->id() === 'VIEW-ID') { // Analyze the structure of your form with kint(). // Say, the field that matters to you is "field_foobar". // kint($form); exit; if (isset($form['field_foobar']) { $form['field_foobar']['#type'] = 'select'; $form['field_foobar']['#multiple'] = FALSE; $form['field_foobar']['#size'] = 1; // TODO: Do other things as necessary. } } } 
added 95 characters in body
Source Link
Jigarius
  • 3.1k
  • 16
  • 21

I can see two possible solutions to this problem:

Solution 1: Better Exposed Filters

Install the Better Exposed Filters module. There are over 31,227 sites using it at the moment. Don't let the fact that it is in alpha hold you back unless your organization has a policy preventing you from using alpha releases.

Solution 2: Custom Code

If you don't wantcannot use Better Exposed Filters for some reason, then write a hook_form_FORM_ID_alter() to modify your views exposed form the way you want.

I can see two possible solutions to this problem:

Solution 1: Better Exposed Filters

Install the Better Exposed Filters module. There are over 31,227 sites using it at the moment. Don't let the fact that it is in alpha hold you back.

Solution 2: Custom Code

If you don't want Better Exposed Filters, then write a hook_form_FORM_ID_alter() to modify your views exposed form the way you want.

I can see two possible solutions to this problem:

Solution 1: Better Exposed Filters

Install the Better Exposed Filters module. There are over 31,227 sites using it at the moment. Don't let the fact that it is in alpha hold you back unless your organization has a policy preventing you from using alpha releases.

Solution 2: Custom Code

If you cannot use Better Exposed Filters for some reason, then write a hook_form_FORM_ID_alter() to modify your views exposed form the way you want.

Source Link
Jigarius
  • 3.1k
  • 16
  • 21

I can see two possible solutions to this problem:

Solution 1: Better Exposed Filters

Install the Better Exposed Filters module. There are over 31,227 sites using it at the moment. Don't let the fact that it is in alpha hold you back.

Solution 2: Custom Code

If you don't want Better Exposed Filters, then write a hook_form_FORM_ID_alter() to modify your views exposed form the way you want.