From e0c20ddf2b2c5b0794186c804af3d615f370ebbd Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Fri, 1 Feb 2019 12:19:52 +0300 Subject: [PATCH] FIX getEditLink is now extensible and Lang route handling has a fallback In some cases the Lang is not available in the route, this fixes that as well as making the getEditLink() method extensible --- code/controllers/DocumentationViewer.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/code/controllers/DocumentationViewer.php b/code/controllers/DocumentationViewer.php index 95b33c3..53b51a2 100755 --- a/code/controllers/DocumentationViewer.php +++ b/code/controllers/DocumentationViewer.php @@ -213,7 +213,6 @@ class DocumentationViewer extends Controller implements PermissionProvider ltrim($url, '/'), strlen($base) ); - } else { } // @@ -276,6 +275,11 @@ class DocumentationViewer extends Controller implements PermissionProvider // return $redirect->redirect($cleaned, 302); // } if ($record = $this->getManifest()->getPage($url)) { + // In SS 3 offsetSet() isn't implemented for some reason... this is a workaround + $routeParams = $this->request->routeParams(); + $routeParams['Lang'] = $lang; + $this->request->setRouteParams($routeParams); + $this->record = $record; $this->init(); @@ -687,10 +691,13 @@ class DocumentationViewer extends Controller implements PermissionProvider /** * Returns an edit link to the current page (optional). * - * @return string + * @return string|false */ public function getEditLink() { + $editLink = false; + $entity = null; + $page = $this->getPage(); if ($page) { @@ -706,13 +713,13 @@ class DocumentationViewer extends Controller implements PermissionProvider } - if ($version == 'trunk' && (isset($url['options']['rewritetrunktomaster']))) { + if ($version === 'trunk' && (isset($url['options']['rewritetrunktomaster']))) { if ($url['options']['rewritetrunktomaster']) { $version = "master"; } } - return str_replace( + $editLink = str_replace( array('%entity%', '%lang%', '%version%', '%path%'), array( $entity->title, @@ -725,7 +732,9 @@ class DocumentationViewer extends Controller implements PermissionProvider } } - return false; + $this->extend('updateDocumentationEditLink', $editLink, $entity); + + return $editLink; }