Source of file MatomoSiteConfigExtension.php
Size: 1,273 Bytes - Last Modified: 2021-12-24T06:46:44+00:00
/var/www/docs.ssmods.com/process/src/src/Extension/MatomoSiteConfigExtension.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 | <?php namespace ElliotSawyer\Matomo; use SilverStripe\Forms\TextField; use SilverStripe\Forms\ToggleCompositeField; use SilverStripe\ORM\DataExtension; class MatomoSiteConfigExtension extends DataExtension { private static $db = [ 'MatomoTrackingURL' => 'Varchar(255)', 'MatomoSiteId' => 'Int' ]; public function updateCMSFields(\SilverStripe\Forms\FieldList $fields) { $fields->addFieldToTab('Root.Analytics', ToggleCompositeField::create( 'MatomoToggle', 'Matomo', [ TextField::create('MatomoTrackingURL', 'Tracking URL'), TextField::create('MatomoSiteId', 'Site ID'), ] ) ); } private function getProtocolAgnosticHostname() { $hostname = rtrim($this->owner->MatomoTrackingURL); $hostname = rtrim($hostname, '/'); $hostname .= '/'; $hostname = ltrim($hostname); $hostname = str_replace(['http://', 'https://', '//'], '', $hostname); $hostname = '//' . $hostname; return $hostname; } public function onBeforeWrite() { $this->owner->MatomoTrackingURL = $this->getProtocolAgnosticHostname(); } } |