Commit 3400fd6d authored by catch's avatar catch
Browse files

Issue #3027705 by claudiu.cristea, Pancho, smustgrave: Allow ?edit[field_xyz]...

Issue #3027705 by claudiu.cristea, Pancho, smustgrave: Allow ?edit[field_xyz] as query parameter in contextual filter

(cherry picked from commit 471c0afd)
parent 137b26e1
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

namespace Drupal\views\Plugin\views\argument_default;

use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\Form\FormStateInterface;
@@ -64,9 +65,12 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
   */
  public function getArgument() {
    $current_request = $this->view->getRequest();
    // Convert a[b][c][d] into ['a', 'b', 'c', 'd'].
    $path = array_filter(preg_split('#(\[|\]\[|\])#', $this->options['query_param']));

    if ($current_request->query->has($this->options['query_param'])) {
      $param = $current_request->query->all()[$this->options['query_param']];
    if ($current_request->query->has($path[0])) {
      $query = $current_request->query->all();
      $param = NestedArray::getValue($query, $path);
      if (is_array($param)) {
        $conjunction = ($this->options['multiple'] == 'and') ? ',' : '+';
        $param = implode($conjunction, $param);
+18 −0
Original line number Diff line number Diff line
@@ -69,6 +69,24 @@ public function providerGetArgument() {
      'blub',
    ];

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

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

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

    return $data;
  }