0

I have a page with a view on it and some exposed inputs. I need to get the results programatically. I can load a view programmatically no problem but setting the exposed input has not been working.

$view = Views::getView('inventory_listing');
$view->initDisplay();
$view->setExposedInput($view->getExposedInput());
$view->preExecute();
$view->execute();

results in ALL the rows, not the ones filtered out. I am running this in my hook_form_alter function because I need to change the display of my exposed filters. That may be part of the problem. Any ideas?

0

I use direct input parameter for right filtering, and it is working for me.

$view = Views::getView('my_view_name');
$view->setDisplay('display_name_from_my_view');
$view->setArguments([ $value1, $value2 ]);
$view->execute();

So, i can take result of $view by

$result = [];
if (empty($view->build_info['fail']) and empty($view->build_info['denied'])) {
    $result = $view->result;
}

After this I can render it or use for another goal.

This site is temporarily in read only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .