Merge branch '2.0'

This commit is contained in:
Robbie Averill 2018-05-25 15:03:11 +12:00
commit 489f8c576f

View File

@ -108,6 +108,9 @@ class JSONDataFormatter extends DataFormatter
if ($this->customRelations && !in_array($relName, $this->customRelations)) { if ($this->customRelations && !in_array($relName, $this->customRelations)) {
continue; continue;
} }
if ($obj->$relName() && (!$obj->$relName()->exists() || !$obj->$relName()->canView())) {
continue;
}
$fieldName = $relName . 'ID'; $fieldName = $relName . 'ID';
$rel = $this->config()->api_base; $rel = $this->config()->api_base;
@ -144,6 +147,9 @@ class JSONDataFormatter extends DataFormatter
$innerParts = array(); $innerParts = array();
$items = $obj->$relName(); $items = $obj->$relName();
foreach ($items as $item) { foreach ($items as $item) {
if (!$item->canView()) {
continue;
}
$rel = $this->config()->api_base . $this->sanitiseClassName($relClass) . "/$item->ID"; $rel = $this->config()->api_base . $this->sanitiseClassName($relClass) . "/$item->ID";
$href = Director::absoluteURL($rel); $href = Director::absoluteURL($rel);
$innerParts[] = ArrayData::array_to_object(array( $innerParts[] = ArrayData::array_to_object(array(