Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
Issue #77: De-couple grid helper from router and template
Browse files Browse the repository at this point in the history
- Add 'url' config option to sort() helper method to pass an HttpUrl object to the helper used to calculate the sort url
- Set the url for sorting based on the config options

BREAKING! The grid.sort helper now has a 'url' config option that needs to be used to create the url for sorting. To migrate your code all template calls to the grid.sort should include array('url' => route());
  • Loading branch information
johanjanssens committed May 3, 2016
1 parent 1184bf0 commit 943f8a3
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions code/template/helper/grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,15 @@ public function checkall($config = array())
* @param array $config An optional array with configuration options
* @return string Html
*/
public function sort($config = array(), TemplateInterface $template)
public function sort($config = array())
{
$config = new ObjectConfigJson($config);
$config->append(array(
'title' => '',
'column' => '',
'direction' => 'asc',
'sort' => ''
'sort' => '',
'url' => null
));

$translator = $this->getObject('translator');
Expand All @@ -191,8 +192,8 @@ public function sort($config = array(), TemplateInterface $template)
}

//Set the direction
$direction = strtolower($config->direction);
$direction = in_array($direction, array('asc', 'desc')) ? $direction : 'asc';
$direction = strtolower($config->direction);
$direction = in_array($direction, array('asc', 'desc')) ? $direction : 'asc';

//Set the class
$class = '';
Expand All @@ -202,14 +203,15 @@ public function sort($config = array(), TemplateInterface $template)
$class = 'class="-koowa-'.$direction.'"';
}

$url = $template->route();
//Set the query in the route
if(!$config->url instanceof HttpUrlInterface) {
$config->url = HttpUrl::fromString($config->url);
}

$query = $url->getQuery(1);
$query['sort'] = $config->column;
$query['direction'] = $direction;
$url->setQuery($query);
$config->url->query['sort'] = $config->column;
$config->url->query['direction'] = $direction;

$html = '<a href="'.$url.'" title="'.$translator->translate('Click to sort by this column').'" '.$class.'>';
$html = '<a href="'.$config->url.'" title="'.$translator->translate('Click to sort by this column').'" '.$class.'>';
$html .= $translator->translate($config->title);

// Mark the current column
Expand Down

0 comments on commit 943f8a3

Please sign in to comment.