0

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?

6
  • Just a thought: perhaps contextual filter could work instead? Sep 2 '21 at 16:12
  • thx, I'll check that :)
    – Andreas
    Sep 3 '21 at 7:14
  • 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.
    – Hudri
    Sep 3 '21 at 9:05
  • 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
    – Andreas
    Sep 3 '21 at 11:34
  • also neither enabling ajax nore using contextual filters changed the unexpected behaviour.
    – Andreas
    Sep 3 '21 at 11:35
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.