From a4f4857a5dcc29ec250fb28500b9d0e2611940bc Mon Sep 17 00:00:00 2001 From: Aaron Valandra Date: Wed, 6 Mar 2019 16:06:39 -0600 Subject: [PATCH] Added item-fields back for specific content types. --- src/Action/SingleAction.php | 2 +- src/Converter/Parameter/Type/Fields.php | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Action/SingleAction.php b/src/Action/SingleAction.php index e576615..af5febc 100644 --- a/src/Action/SingleAction.php +++ b/src/Action/SingleAction.php @@ -77,7 +77,7 @@ public function handle($contentType, $slug, $relatedContentType, Request $reques } else { //$allFields = $this->APIHelper->getAllFieldNames($contentType); //$fields = $this->APIHelper->getFields($contentType, $allFields, 'item-fields'); - $fields = $parameters->get('fields')->getFields(); + $fields = $parameters->get('fields')->getFields(null, 'getItemFields'); $values = $this->parser->parseItem($results, $fields); //@todo get previous and next link $prev = $results->previous(); diff --git a/src/Converter/Parameter/Type/Fields.php b/src/Converter/Parameter/Type/Fields.php index 88a82d3..71eb7fd 100644 --- a/src/Converter/Parameter/Type/Fields.php +++ b/src/Converter/Parameter/Type/Fields.php @@ -33,7 +33,7 @@ public function convertRequest() return $this; } - protected function getFieldsForContentType($contentType) + protected function getFieldsForContentType($contentType, $fallbackFields = 'getListFields') { if ($this->config->getAllowedFields($contentType)) { $allowedFields = $this->config->getAllowedFields($contentType); @@ -53,8 +53,8 @@ protected function getFieldsForContentType($contentType) // Default on the default/fallback fields defined in the config. if (empty($this->fields[$contentType])) { $this->fields[$contentType] = $allowedFields; - if ($this->config->getListFields($contentType)) { - $this->fields[$contentType] = $this->config->getListFields($contentType); + if ($this->config->$fallbackFields($contentType)) { + $this->fields[$contentType] = $this->config->$fallbackFields($contentType); // todo: do we need to filter these through 'allowed-fields'? } } @@ -76,8 +76,15 @@ public function getParameter() /** * @return array */ - public function getFields($contentType = null) + public function getFields($contentType = null, $itemFields = null) { + if ($itemFields) { + $contentType = ($contentType !== null ?: $this->contentType); + $this->getFieldsForContentType($contentType, 'getItemFields'); + + return $this->fields[$contentType]; + } + if (! $contentType) { return $this->fields[$this->contentType]; }