Skip to content

Commit 9fe40e7

Browse files
SearchEditor: Allow setting a Filter directly instead of a queryString
1 parent 8eb3caa commit 9fe40e7

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

src/Control/SearchEditor.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class SearchEditor extends Form
6363
* Set the filter query string to populate the form with
6464
*
6565
* Use {@see SearchEditor::getParser()} to subscribe to parser events.
66+
* Calling this resets any filter previously set by {@see SearchEditor::setFilter()}
6667
*
6768
* @param string $query
6869
*
@@ -71,6 +72,7 @@ class SearchEditor extends Form
7172
public function setQueryString($query)
7273
{
7374
$this->queryString = $query;
75+
$this->filter = null;
7476

7577
return $this;
7678
}
@@ -149,6 +151,25 @@ public function getFilter()
149151
return $this->filter;
150152
}
151153

154+
/**
155+
* Set the filter to populate the form with
156+
*
157+
* Overwrites any query string previously set by {@see SearchEditor::setQueryString()}.
158+
*
159+
* @param Filter\Rule $filter
160+
*
161+
* @return $this
162+
*/
163+
public function setFilter(Filter\Rule $filter): static
164+
{
165+
$this->filter = $filter;
166+
$this->queryString = $filter instanceof Filter\Chain && $filter->isEmpty()
167+
? ''
168+
: (new Renderer($filter))->setStrict()->render();
169+
170+
return $this;
171+
}
172+
152173
/**
153174
* Get inline stylesheet
154175
*

0 commit comments

Comments
 (0)