mirror of
https://github.com/silverstripe/silverstripe-subsites
synced 2024-10-22 11:05:55 +02:00
parent
40b8e102d0
commit
774dee91d6
@ -347,11 +347,15 @@ class SiteTreeSubsites extends DataExtension
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function alternateAbsoluteLink()
|
/**
|
||||||
|
* @param null $action
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function alternateAbsoluteLink($action = null)
|
||||||
{
|
{
|
||||||
// Generate the existing absolute URL and replace the domain with the subsite domain.
|
// Generate the existing absolute URL and replace the domain with the subsite domain.
|
||||||
// This helps deal with Link() returning an absolute URL.
|
// This helps deal with Link() returning an absolute URL.
|
||||||
$url = Director::absoluteURL($this->owner->Link());
|
$url = Director::absoluteURL($this->owner->Link($action));
|
||||||
if ($this->owner->SubsiteID) {
|
if ($this->owner->SubsiteID) {
|
||||||
$url = preg_replace('/\/\/[^\/]+\//', '//' . $this->owner->Subsite()->domain() . '/', $url);
|
$url = preg_replace('/\/\/[^\/]+\//', '//' . $this->owner->Subsite()->domain() . '/', $url);
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
namespace SilverStripe\Subsites\Tests;
|
namespace SilverStripe\Subsites\Tests;
|
||||||
|
|
||||||
use Page;
|
use Page;
|
||||||
use SilverStripe\Assets\FileNameFilter;
|
|
||||||
use SilverStripe\CMS\Controllers\CMSMain;
|
use SilverStripe\CMS\Controllers\CMSMain;
|
||||||
use SilverStripe\CMS\Controllers\ModelAsController;
|
use SilverStripe\CMS\Controllers\ModelAsController;
|
||||||
use SilverStripe\CMS\Model\SiteTree;
|
use SilverStripe\CMS\Model\SiteTree;
|
||||||
@ -399,4 +398,33 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
|
|||||||
'Themes should be modified when Subsite has theme defined'
|
'Themes should be modified when Subsite has theme defined'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function provideAlternateAbsoluteLink()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
['home', null, 'http://localhost/'],
|
||||||
|
['home', 'myaction', 'http://localhost/home/myaction'],
|
||||||
|
['contact', null, 'http://localhost/contact-us/'],
|
||||||
|
['contact', 'myaction', 'http://localhost/contact-us/myaction'],
|
||||||
|
['subsite1_home', null, 'http://subsite1.localhost/'],
|
||||||
|
['subsite1_home', 'myaction', 'http://subsite1.localhost/home/myaction'],
|
||||||
|
['subsite1_contactus', null, 'http://subsite1.localhost/contact-us/'],
|
||||||
|
['subsite1_contactus', 'myaction', 'http://subsite1.localhost/contact-us/myaction']
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider provideAlternateAbsoluteLink
|
||||||
|
* @param $fixture
|
||||||
|
* @param $expected
|
||||||
|
*/
|
||||||
|
public function testAlternateAbsoluteLink($pageFixtureName, $action, $expectedAbsoluteLink)
|
||||||
|
{
|
||||||
|
/** @var Page $page */
|
||||||
|
$page = $this->objFromFixture('Page', $pageFixtureName);
|
||||||
|
|
||||||
|
$result = $page->AbsoluteLink($action);
|
||||||
|
|
||||||
|
$this->assertEquals($expectedAbsoluteLink, $result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user