addDependency('acl'); $this->addDependency('layout'); $this->addDependency('metadata'); } protected function getAcl() { return $this->getInjection('acl'); } protected function getMetadata() { return $this->getInjection('metadata'); } public function getForFrontend(string $scope, string $name) { $dataString = $this->getInjection('layout')->get($scope, $name); if (!$dataString) { throw new NotFound("Layout {$scope}:{$scope} is not found."); } if (!$this->getUser()->isAdmin()) { if ($name === 'relationships') { $data = json_decode($dataString); if (is_array($data)) { foreach ($data as $i => $link) { $foreignEntityType = $this->getMetadata()->get(['entityDefs', $scope, 'links', $link, 'entity']); if ($foreignEntityType) { if (!$this->getAcl()->check($foreignEntityType)) { unset($data[$i]); } } } $data = array_values($data); $dataString = json_encode($data); } } } return $dataString; } }