Score:0

Calling setExposedInput() from a Drush command doesn't have any effect

ve flag

We have a custom Drush command implemented using the following code.

class JobApplicationExportCommands extends DrushCommands {

  /**
   * Exports Dorea Job Applications since the last run to csv
   *
   * @command dummy:job-application-export
   * @aliases duje
   */
  public function drush_dummy_export() {
    $applicationWebformIds = Drupal::entityQuery('webform')
      ->condition('category', 'Bewerbungsformulare')
      ->execute();

    $applicationView = Views::getView('all_applications');
    $applicationView->setDisplay('default');
    $applicationView->setExposedInput([
      'webform_ids' => array_keys($applicationWebformIds),
      'submitted' => '2021-01-01'
    ]);

    $applicationView->execute();

    // This outputs 0, which is wrong.
    print_r(count($applicationView->result));
  }

}

The view configuration is the following.

screenshot

If I execute the same logic via a custom controller / normal request, the view does return values.

Am I missing something? Does anybody know why the exposed input of the view is ignored?

us flag
Just a thought: perhaps contextual filter could work instead?
ve flag
thx, I'll check that :)
ru flag
I once had a weird issue where `setExposedInput` was only working when `use ajax` was enabled in views advanced settings. Not sure why and if it helps here, but worth trying.
ve flag
The funny thing is, that even if I drop the exposed input. and go via the more hardcoded approach of `hook_views_query_alter` I get 0 results via drush
ve flag
also neither enabling ajax nore using contextual filters changed the unexpected behaviour.
ve flag
Uh! I think it has something to do with the user - if I'm not logged in as admin, I also get 0 results via the frontend.
Score:0
ve flag

Alright, a colleague saved me again: The access checks can be dissabled individually per view via Query settings > Disable SQL rewriting

enter image description here

For this particular view and usecase this is exactly what is needed, as it is only callable by backend processes.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.