diff --git a/code/Model/RedirectorPage.php b/code/Model/RedirectorPage.php index 97124f32ce..6eaec82686 100644 --- a/code/Model/RedirectorPage.php +++ b/code/Model/RedirectorPage.php @@ -7,6 +7,7 @@ use SilverStripe\Forms\FieldList; use SilverStripe\Forms\HeaderField; use SilverStripe\Forms\OptionsetField; +use SilverStripe\Forms\UrlField; use SilverStripe\Versioned\Versioned; /** @@ -47,6 +48,9 @@ class RedirectorPage extends Page 'RedirectionType', 'Content', ], + 'fieldClasses' => [ + 'ExternalURL' => UrlField::class, + ], ]; private static $table_name = 'RedirectorPage'; @@ -171,35 +175,12 @@ public function syncLinkTracking() } } - protected function onBeforeWrite() - { - parent::onBeforeWrite(); - - if ($this->ExternalURL && substr($this->ExternalURL ?? '', 0, 2) !== '//') { - $urlParts = parse_url($this->ExternalURL ?? ''); - if ($urlParts) { - if (empty($urlParts['scheme'])) { - // no scheme, assume http - $this->ExternalURL = 'http://' . $this->ExternalURL; - } elseif (!in_array($urlParts['scheme'], [ - 'http', - 'https', - ])) { - // we only allow http(s) urls - $this->ExternalURL = ''; - } - } else { - // malformed URL to reject - $this->ExternalURL = ''; - } - } - } - public function getCMSFields() { $this->beforeUpdateCMSFields(function (FieldList $fields) { // Remove all metadata fields, does not apply for redirector pages $fields->removeByName('Metadata'); + $fields->dataFieldByName('ExternalURL')?->setAllowRelativeProtocol(true); $fields->addFieldsToTab( 'Root.Main',