From 4fb947d0c7f9b51eed25c4b93aa25ac801cf185f Mon Sep 17 00:00:00 2001 From: Dylan Wagstaff Date: Wed, 22 Nov 2017 17:11:34 +1300 Subject: [PATCH] FIX: Use new resource loading syntax for javascript SilverStripe 4 vendormodule types make use of an 'expose' composer directive to allow assets they provide to be accessed by a web request. Previously the javascript for the iFrame resizing business tried to load from a static path that no longer exists (referenced inside PHP), which caused a fatal error. This has been fixed along with making the conditional code for enforcing a protocol on the page's request a bit more readable & easily digestable to developers. --- code/IFramePageController.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/code/IFramePageController.php b/code/IFramePageController.php index 1360236..2bea203 100644 --- a/code/IFramePageController.php +++ b/code/IFramePageController.php @@ -11,17 +11,19 @@ class IFramePageController extends ContentController protected function init() { parent::init(); - - if ($this->ForceProtocol) { - if ($this->ForceProtocol == 'http://' && Director::protocol() != 'http://') { - return $this->redirect(preg_replace('#https://#', 'http://', $this->AbsoluteLink())); - } elseif ($this->ForceProtocol == 'https://' && Director::protocol() != 'https://') { - return $this->redirect(preg_replace('#http://#', 'https://', $this->AbsoluteLink())); - } + $currentProtocol = Director::protocol(); + $desiredProtocol = $this->ForceProtocol; + if ($desiredProtocol && $currentProtocol !== $desiredProtocol) { + $enforcedLocation = preg_replace( + "#^${currentProtocol}#", + $desiredProtocol, + $this->AbsoluteLink() + ); + return $this->redirect($enforcedLocation); } if ($this->IFrameURL) { - Requirements::javascript('iframe/javascript/iframe_page.js'); + Requirements::javascript('silverstripe/iframe: javascript/iframe_page.js'); } } }