silverstripe-iframe/code/IFramePageController.php
Dylan Wagstaff 4fb947d0c7 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.
2017-11-22 17:11:34 +13:00

30 lines
827 B
PHP

<?php
namespace SilverStripe\IFrame;
use SilverStripe\CMS\Controllers\ContentController;
use SilverStripe\Control\Director;
use SilverStripe\View\Requirements;
class IFramePageController extends ContentController
{
protected function init()
{
parent::init();
$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('silverstripe/iframe: javascript/iframe_page.js');
}
}
}