How do I programmatically render a view that has exposed filters?
Solutions
You can use this code in custom block can also set permission.
use Drupal\Core\Form\FormState;
use Drupal\views\Views;
$form = [];
$view_id = 'blog_landing_page';
$display_id = 'page_1';
$view = Views::getView($view_id);
if ($view) {
$view->setDisplay($display_id);
$view->initHandlers();
$form_state = (new FormState())
->setStorage([
'view' => $view,
'display' => &$view->display_handler->display,
'rerender' => TRUE,
])
->setMethod('get')
->setAlwaysProcess()
->disableRedirect();
$form_state->set('rerender', NULL);
$form = \Drupal::formBuilder()->buildForm('\Drupal\views\Form\ViewsExposedForm', $form_state);
}
Programmatically get exposed filters from view
A little bit of context: I am running a headless Drupal 8 with React in the front-end. All the data gets exposed through various endpoints. Now i am trying to render a view in react, there was no problem in obtaining the data. But when i tried to get the exposed filters i ran into a problem (the filters are based on taxonomy terms). I expected to g...
How to get a view result programmatically without exposed filters respected
I have some views of display page which I do not want to show to public if there would not be any result when accessed without any exposed filters set. I have a custom views access plugin and a custom access checking class which can handle the access granting. My idea so far is that I would like to run the view a first time during access checking w...
Adding custom classes to Views Filters (view-filters) and Content (div.view-contents)
I'm using a theme that includes bootstrap. I'd like to inject class one_third into <div class="view-filters"> and two_third last to <div class="view-content">. Is there a way to do so from any theme theme_preprocess_area? I know I could accomplish using javascript (selecting div.view-filters and addClass()), but I think it would be most...
Printing views exposed sort criteria separately to exposed filters
Exposed filters are either: - Printed in views-view.tpl.php using the $exposed variable. - Printed in a block, probably using the same variable. This variable ($exposed) contains the exposed sort criteria and filters. I would like to find a way to print them separately. Ideally there would be a way to use something like: Does anyone know of a way y...
combine several exposed filters into one exposed (search) form?
Is there an easy way to combine two or more exposed filters into one shared exposed form? So that I don't have to have several search fields for each and every field that I want to filter. Is this possible? Any modules that does this? I am using the Better Exposed Filters module. Thanks in advance