Commit 88e353b1 authored by Andrey Vitushkin's avatar Andrey Vitushkin
Browse files

Issue #3313529 by kbeck303, EPAM Systems: "Is empty (NULL)" and "Is not empty...

Issue #3313529 by kbeck303, EPAM Systems: "Is empty (NULL)" and "Is not empty (NOT NULL)" causes an error.
parent 93e372c2
Loading
Loading
Loading
Loading
+19 −5
Original line number Diff line number Diff line
@@ -44,13 +44,18 @@ class UrlAliasFilter extends StringFilter {
      $nids[] = str_replace('/node/', '', $path);
    }

    if ($nids) {
    if (count($nids) === 0) {
      // If aliases was not found then add the condition to return nothing.
      $this->query->addWhere($this->options['group'], (new Condition('AND'))->alwaysFalse());
    }
    else {
      $field = "$this->tableAlias.$this->realField";
      $this->query->addWhere($this->options['group'], $field, $nids, 'IN');
      if ($this->operator === 'empty') {
        $this->query->addWhere($this->options['group'], $field, $nids, 'NOT IN');
      }
      else {
      // If aliases was not found then add the condition to return nothing.
      $this->query->addWhere($this->options['group'], (new Condition('AND'))->alwaysFalse());
        $this->query->addWhere($this->options['group'], $field, $nids, 'IN');
      }
    }
  }

@@ -170,4 +175,13 @@ class UrlAliasFilter extends StringFilter {
    $this->queryPaths->condition($field, $this->value, 'REGEXP');
  }

  /**
   * We do not add additional condition for opEmpty operator here.
   *
   * "addWhere" for "empty" operator added in the "query()" function.
   * Just override this method and leave it empty (to avoid an error).
   */
  protected function opEmpty($field) {
  }

}
+1 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ function views_alias_filter_views_data_alter(array &$data) {
      'help' => t('Filtering nodes by URL aliases.'),
      'field' => 'nid',
      'id' => 'url_alias_filter',
      'allow empty' => TRUE,
    ],
  ];
}