FilterEditor: use preserved params

fixes #7904
This commit is contained in:
Thomas Gelf 2015-02-02 17:07:54 +01:00
parent c4c6d36b00
commit 3596e7ce62
1 changed files with 21 additions and 8 deletions

View File

@ -34,6 +34,10 @@ class FilterEditor extends AbstractWidget
protected $preserveParams = array(); protected $preserveParams = array();
protected $preservedParams = array();
protected $preservedUrl;
protected $ignoreParams = array(); protected $ignoreParams = array();
/** /**
@ -84,6 +88,14 @@ class FilterEditor extends AbstractWidget
return $this->url; return $this->url;
} }
protected function preservedUrl()
{
if ($this->preservedUrl === null) {
$this->preservedUrl = $this->url()->with($this->preservedParams);
}
return $this->preservedUrl;
}
public function setQuery($query) public function setQuery($query)
{ {
$this->query = $query; $this->query = $query;
@ -147,6 +159,7 @@ class FilterEditor extends AbstractWidget
$preserve[$key] = $value; $preserve[$key] = $value;
} }
} }
$this->preservedParams = $preserve;
$add = $params->shift('addFilter'); $add = $params->shift('addFilter');
$remove = $params->shift('removeFilter'); $remove = $params->shift('removeFilter');
@ -232,7 +245,7 @@ class FilterEditor extends AbstractWidget
if ($modify) { if ($modify) {
if ($request->isPost()) { if ($request->isPost()) {
if ($request->get('cancel') === 'Cancel') { if ($request->get('cancel') === 'Cancel') {
$this->redirectNow($this->url()->without('modifyFilter')); $this->redirectNow($this->preservedUrl()->without('modifyFilter'));
} }
$filter = $this->applyChanges($request->getPost()); $filter = $this->applyChanges($request->getPost());
@ -295,7 +308,7 @@ class FilterEditor extends AbstractWidget
{ {
return $this->view()->qlink( return $this->view()->qlink(
'', '',
$this->url()->with('removeFilter', $filter->getId()), $this->preservedUrl()->with('removeFilter', $filter->getId()),
null, null,
array( array(
'title' => t('Click to remove this part of your filter'), 'title' => t('Click to remove this part of your filter'),
@ -308,7 +321,7 @@ class FilterEditor extends AbstractWidget
{ {
return $this->view()->qlink( return $this->view()->qlink(
'', '',
$this->url()->with('addFilter', $filter->getId()), $this->preservedUrl()->with('addFilter', $filter->getId()),
null, null,
array( array(
'title' => t('Click to add another filter'), 'title' => t('Click to add another filter'),
@ -321,7 +334,7 @@ class FilterEditor extends AbstractWidget
{ {
return $this->view()->qlink( return $this->view()->qlink(
'', '',
$this->url()->with('stripFilter', $filter->getId()), $this->preservedUrl()->with('stripFilter', $filter->getId()),
null, null,
array( array(
'title' => t('Strip this filter'), 'title' => t('Strip this filter'),
@ -334,7 +347,7 @@ class FilterEditor extends AbstractWidget
{ {
return $this->view()->qlink( return $this->view()->qlink(
'', '',
$this->url()->without('addFilter'), $this->preservedUrl()->without('addFilter'),
null, null,
array( array(
'title' => t('Cancel this operation'), 'title' => t('Cancel this operation'),
@ -638,7 +651,7 @@ class FilterEditor extends AbstractWidget
public function renderSearch() public function renderSearch()
{ {
$html = ' <form method="post" class="inline dontprint" action="' $html = ' <form method="post" class="inline dontprint" action="'
. $this->url() . $this->preservedUrl()
. '"><input type="text" name="q" style="width: 8em" class="search" value="" placeholder="' . '"><input type="text" name="q" style="width: 8em" class="search" value="" placeholder="'
. t('Search...') . t('Search...')
. '" /></form>'; . '" /></form>';
@ -653,7 +666,7 @@ class FilterEditor extends AbstractWidget
} }
return $html return $html
. '<a href="' . '<a href="'
. $this->url()->with('modifyFilter', true) . $this->preservedUrl()->with('modifyFilter', true)
. '" title="' . '" title="'
. $title . $title
. '">' . '">'
@ -663,7 +676,7 @@ class FilterEditor extends AbstractWidget
public function render() public function render()
{ {
if (! $this->url()->getParam('modifyFilter')) { if (! $this->preservedUrl()->getParam('modifyFilter')) {
return $this->renderSearch() . $this->shorten($this->filter, 50); return $this->renderSearch() . $this->shorten($this->filter, 50);
} }
return $this->renderSearch() return $this->renderSearch()