From d9a74f4c1302967f3cb2e7d6062bb194e2a4395f Mon Sep 17 00:00:00 2001 From: Christopher Pitt Date: Tue, 7 May 2019 19:30:55 +0200 Subject: [PATCH 1/3] Use array_merge instead of addition operator Using the addition operator, like this, means _archived and _draft cannot be provided by $fields. Array merge avoids this problem by overwriting the $defaults values with those present in $fields. --- src/Webflow/Api.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Webflow/Api.php b/src/Webflow/Api.php index 8adf9ba..9e5bdcd 100644 --- a/src/Webflow/Api.php +++ b/src/Webflow/Api.php @@ -163,11 +163,12 @@ public function item(string $collectionId, string $itemId) public function createItem(string $collectionId, array $fields) { $defaults = [ - "_archived" => false, - "_draft" => false, + "_archived" => false, + "_draft" => false, ]; + return $this->post("/collections/{$collectionId}/items", [ - 'fields' => $defaults + $fields, + 'fields' => array_merge($defaults, $fields), ]); } From c64759f05b924d9030b7712a8f80f356743660b9 Mon Sep 17 00:00:00 2001 From: Christopher Pitt Date: Tue, 7 May 2019 19:32:25 +0200 Subject: [PATCH 2/3] Format updateItem fields like createItem fields This makes updateItem work similarly to createItem, and avoids the need to further nest $fields at the call-site. --- src/Webflow/Api.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Webflow/Api.php b/src/Webflow/Api.php index 9e5bdcd..5c46f9f 100644 --- a/src/Webflow/Api.php +++ b/src/Webflow/Api.php @@ -174,7 +174,9 @@ public function createItem(string $collectionId, array $fields) public function updateItem(string $collectionId, string $itemId, array $fields) { - return $this->put("/collections/{$collectionId}/items/{$itemId}", $fields); + return $this->put("/collections/{$collectionId}/items/{$itemId}", [ + 'fields' => $fields, + ]); } public function removeItem(string $collectionId, $itemId) From b9f689fda8a95d47b9ccaf1f3be09edc5f606a82 Mon Sep 17 00:00:00 2001 From: Christopher Pitt Date: Tue, 7 May 2019 19:33:37 +0200 Subject: [PATCH 3/3] Remove the $data attribute, for delete() The only place delete() is called is in removeItem(), which doesn't require parameters. --- src/Webflow/Api.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Webflow/Api.php b/src/Webflow/Api.php index 5c46f9f..aaf4564 100644 --- a/src/Webflow/Api.php +++ b/src/Webflow/Api.php @@ -76,9 +76,9 @@ private function put($path, $data) return $this->request($path, "PUT", $data); } - private function delete($path, $data) + private function delete($path) { - return $this->request($path, "DELETE", $data); + return $this->request($path, "DELETE"); } private function parse($response)