From 33d61482c0505ccf3276b693aa2d2d2e22631abe Mon Sep 17 00:00:00 2001 From: Johannes Wachter Date: Tue, 2 Aug 2016 09:50:01 +0200 Subject: [PATCH] added type param --- Content/ArticleDataProvider.php | 16 +++++++++++++++- Resources/config/services.xml | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Content/ArticleDataProvider.php b/Content/ArticleDataProvider.php index 4062e5b92..cf85fc2e9 100644 --- a/Content/ArticleDataProvider.php +++ b/Content/ArticleDataProvider.php @@ -21,6 +21,7 @@ use ProxyManager\Proxy\LazyLoadingInterface; use Sulu\Bundle\ArticleBundle\Document\ArticleDocument; use Sulu\Bundle\ArticleBundle\Document\ArticleOngrDocument; +use Sulu\Component\Content\Compat\PropertyParameter; use Sulu\Component\DocumentManager\DocumentManagerInterface; use Sulu\Component\SmartContent\Configuration\Builder; use Sulu\Component\SmartContent\DataProviderInterface; @@ -81,7 +82,7 @@ public function getConfiguration() */ public function getDefaultPropertyParameter() { - return []; + return ['type' => new PropertyParameter('type', null)]; } /** @@ -95,6 +96,10 @@ public function resolveDataItems( $page = 1, $pageSize = null ) { + if (array_key_exists('type', $propertyParameter) && null !== ($type = $propertyParameter['type']->getValue())) { + $filters['type'] = $type; + } + $result = []; $uuids = []; /** @var ArticleOngrDocument $document */ @@ -117,6 +122,10 @@ public function resolveResourceItems( $page = 1, $pageSize = null ) { + if (array_key_exists('type', $propertyParameter) && null !== ($type = $propertyParameter['type']->getValue())) { + $filters['type'] = $type; + } + $result = []; $uuids = []; /** @var ArticleOngrDocument $document */ @@ -167,6 +176,11 @@ private function getSearchResult(array $filters, $limit, $page, $pageSize) $operator = $this->getFilter($filters, 'websiteCategoriesOperator', 'or'); $this->addBoolQuery('websiteCategories', $filters, 'excerpt.categories', $operator, $query, $queriesCount); + if (array_key_exists('type', $filters)) { + $query->add(new TermQuery('type', $filters['type'])); + $queriesCount++; + } + if (0 === $queriesCount) { $search->addQuery(new MatchAllQuery()); } else { diff --git a/Resources/config/services.xml b/Resources/config/services.xml index 11f99a725..74524a54e 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -85,7 +85,7 @@ - +