diff --git a/src/Netzmacht/Contao/Leaflet/Frontend/DataController.php b/src/Netzmacht/Contao/Leaflet/Frontend/DataController.php index 22db74f..b825057 100644 --- a/src/Netzmacht/Contao/Leaflet/Frontend/DataController.php +++ b/src/Netzmacht/Contao/Leaflet/Frontend/DataController.php @@ -58,6 +58,15 @@ class DataController $format = $this->getInput('format', 'geojson'); $type = $this->getInput('type', 'layer'); $dataId = $this->getInput('id'); + $page = \Input::get('page', true); + + if ($page) { + // Fake a page request. + \Environment::set('request', base64_decode($page)); + + // We need the auto_item being set. So call the getPageIdFromUrl method, this does it internally. + \Frontend::getPageIdFromUrl(); + } try { list($data, $error) = $this->loadData($type, $dataId); diff --git a/src/Netzmacht/Contao/Leaflet/Frontend/RequestUrl.php b/src/Netzmacht/Contao/Leaflet/Frontend/RequestUrl.php index 1858c55..d7adfff 100644 --- a/src/Netzmacht/Contao/Leaflet/Frontend/RequestUrl.php +++ b/src/Netzmacht/Contao/Leaflet/Frontend/RequestUrl.php @@ -53,8 +53,25 @@ class RequestUrl ->setPath($path) ->setQueryParameter('type', $type ?: 'layer') ->setQueryParameter('format', $format ?: 'geojson') - ->setQueryParameter('id', $dataId); + ->setQueryParameter('id', $dataId) + ->setQueryParameter('page', rawurlencode(base64_encode(self::getRequestUri()))); return $builder; } + + /** + * Get the request uri without leading slash. + * + * @return mixed + */ + protected static function getRequestUri() + { + $uri = \Environment::get('requestUri'); + + if (strpos($uri, '/') === 0) { + return substr($uri, 1); + } + + return $uri; + } }