I have created two VBO custom action buttons. One prints orders, the other updates them. Clicking one disables it and the other until the page reloads (losing all checked orders).
How can I have the print button rebuild/refresh/reload the page or otherwise make the buttons available again and maintain the checked items, if possible.
Here is the unique code for the two buttons:
class PrintOrderAction extends ViewsBulkOperationsActionBase implements ContainerFactoryPluginInterface {
...
public function execute(Order $order = NULL) {
$this->executeMultiple([$order]);
return $this->t('Order Invoice(s) Printed');
}
public function executeMultiple(array $orders) {
try {
(new StreamedResponse(function() use ($orders){
$this->printBuilder->deliverPrintable($orders, $this->entityPrintPluginManager->createSelectedInstance('pdf'), TRUE);
}))->send();
}
catch (PrintEngineException $e){
$this->messenger()->addError(new FormattableMarkup(Xss::filter($e->getMessage()), []));
}
}
}
...
class FulfillOrderAction extends ViewsBulkOperationsActionBase {
...
public function execute(Order $order = NULL) {
if(!$state = $order->getState()){
return $this->t('Order #:number can\'t change state',[
':number' => $order->getOrderNumber(),
]);
}
$order_state_transitions = $state->getTransitions();
if(!is_null($order_state_transitions['validate'])) {
$state->applyTransition($order_state_transitions['validate']);
$order->save();
}
return $this->t('Order #:number marked fulfill', [
':number' => $order->getOrderNumber(),
]);
}
}
EDIT: I believe this has to do with the StreamedResponse and how it doesn't reload the page, but leaves the form essentially unusable. For example, if I select two items to print, print them and then try to print those two again, nothing happens. If I select other items to print, it tries to do something, but eventually times out.
Is Drupal freezing the form in some way that prohibits further submissions, perhaps in some effort to eliminate double submissions? If so, is there some way to disable that for this particular form?
Does that even make sense. Really struggling with this one.