Skip to content

Commit

Permalink
FIX: Use new resource loading syntax for javascript
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Dylan Wagstaff committed Nov 22, 2017
1 parent e394d90 commit 4fb947d
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions code/IFramePageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
}

0 comments on commit 4fb947d

Please sign in to comment.