diff --git a/src/DataFormatter/JSONDataFormatter.php b/src/DataFormatter/JSONDataFormatter.php index cac7bda..cd4840c 100644 --- a/src/DataFormatter/JSONDataFormatter.php +++ b/src/DataFormatter/JSONDataFormatter.php @@ -106,6 +106,9 @@ class JSONDataFormatter extends DataFormatter if ($this->customRelations && !in_array($relName, $this->customRelations)) { continue; } + if ($obj->$relName() && (!$obj->$relName()->exists() || !$obj->$relName()->canView())) { + continue; + } $fieldName = $relName . 'ID'; $rel = $this->config()->api_base; @@ -140,6 +143,9 @@ class JSONDataFormatter extends DataFormatter $innerParts = array(); $items = $obj->$relName(); foreach ($items as $item) { + if (!$item->canView()) { + continue; + } $rel = $this->config()->api_base . $this->sanitiseClassName($relClass) . "/$item->ID"; $href = Director::absoluteURL($rel); $innerParts[] = ArrayData::array_to_object(array(