Verified Commit de90f3f1 authored by godotislate's avatar godotislate
Browse files

fix: #3593838 Views QueryParameter argument_default plugin doesn't apply...

fix: #3593838 Views QueryParameter argument_default plugin doesn't apply default value if root-level parameter key is present, but nested key is missing

By: huzooka
(cherry picked from commit ecf6584e)
parent 9c6b58ef
Loading
Loading
Loading
Loading
Loading
+6 −7
Original line number Diff line number Diff line
@@ -69,9 +69,9 @@ public function getArgument() {
    // Convert a[b][c][d] into ['a', 'b', 'c', 'd'].
    $path = array_filter(preg_split('#(\[|\]\[|\])#', $this->options['query_param']));

    if ($current_request->query->has($path[0])) {
    $query = $current_request->query->all();
      $param = NestedArray::getValue($query, $path);
    $param = NestedArray::getValue($query, $path, $key_exists);
    if ($key_exists) {
      if (is_array($param)) {
        $conjunction = ($this->options['multiple'] == 'and') ? ',' : '+';
        $param = implode($conjunction, $param);
@@ -79,11 +79,10 @@ public function getArgument() {

      return $param;
    }
    else {

    // Otherwise, use the fixed fallback value.
    return $this->options['fallback'];
  }
  }

  /**
   * {@inheritdoc}
+12 −0
Original line number Diff line number Diff line
@@ -91,6 +91,18 @@ public static function providerGetArgument() {
      NULL,
    ];

    $data[] = [
      ['query_param' => 'test[tier1][tier2]', 'fallback' => 'baz'],
      new Request(['test' => ['tier1' => 'foo']]),
      'baz',
    ];

    $data[] = [
      ['query_param' => 'test[tier1][tier2]', 'fallback' => 'baz'],
      new Request(['test' => ['test2' => 'foo']]),
      'baz',
    ];

    return $data;
  }