代码方式获取 Views 中的过滤器表单

use Drupal\Core\Form\FormState;
use Drupal\views\Views;

$form = [];
$view_id = 'your_view_id';
$display_id = 'your_display_id';
$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);
}

参考文章:https://blog.werk21.de/2017/03/08/programmatically-render-exposed-filter-form