Skip to content

Commit

Permalink
Merge pull request #24 from Raistlfiren/parser-refactor
Browse files Browse the repository at this point in the history
Added the ability to add a default sort order based upon the config.yml
  • Loading branch information
Raistlfiren authored Aug 1, 2016
2 parents d849040 + 1f3a1ea commit 47b95c8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions config/config.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ contenttypes:
# query parameter.
where-clause:
status: 'published'
# The `order` clause allows you to set the default order by when querying results
order: -datepublish
pages:
# To use the defaults for a contenttype, just leave its entry empty.
# This will include all user-defined fields and taxonomies in the
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ contenttypes:
allowed-fields: [ title, slug, teaser, image ]
where-clause:
status: 'published'
order: title,-datepublished
pages:
# use 'default' settings
```
Expand Down
12 changes: 12 additions & 0 deletions src/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,4 +307,16 @@ public function getAllowedFields($contentType)

return [];
}

/**
* @return string
*/
public function getSort($contentType)
{
if (isset($this->contentTypes[$contentType]['order'])) {
return $this->contentTypes[$contentType]['order'];
}

return '';
}
}
6 changes: 5 additions & 1 deletion src/Converter/Parameter/Type/Sort.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function convertRequest()

public function findConfigValues()
{

return $this->config->getSort($this->contentType);
}

/**
Expand All @@ -45,6 +45,10 @@ public function getParameter()
*/
public function getSort()
{
if (! empty($this->findConfigValues())) {
return $this->findConfigValues() . ',' . $this->sort;
}

return $this->sort;
}

Expand Down

0 comments on commit 47b95c8

Please sign in to comment.