mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
Merge branch '5.1' into 5
This commit is contained in:
commit
1f1b64f890
@ -104,20 +104,22 @@ class ModelAsController extends Controller implements NestedController
|
|||||||
public function getNestedController(): ContentController
|
public function getNestedController(): ContentController
|
||||||
{
|
{
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
|
$urlSegment = $request->param('URLSegment');
|
||||||
|
|
||||||
if (!$URLSegment = $request->param('URLSegment')) {
|
if ($urlSegment === false || $urlSegment === null || $urlSegment === '') {
|
||||||
throw new Exception('ModelAsController->getNestedController(): was not passed a URLSegment value.');
|
throw new Exception('ModelAsController->getNestedController(): was not passed a URLSegment value.');
|
||||||
}
|
}
|
||||||
|
|
||||||
// url encode unless it's multibyte (already pre-encoded in the database)
|
// url encode unless it's multibyte (already pre-encoded in the database)
|
||||||
$filter = URLSegmentFilter::create();
|
$filter = URLSegmentFilter::create();
|
||||||
|
|
||||||
if (!$filter->getAllowMultibyte()) {
|
if (!$filter->getAllowMultibyte()) {
|
||||||
$URLSegment = rawurlencode($URLSegment ?? '');
|
$urlSegment = rawurlencode($urlSegment ?? '');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Select child page
|
// Select child page
|
||||||
$tableName = DataObject::singleton(SiteTree::class)->baseTable();
|
$tableName = DataObject::singleton(SiteTree::class)->baseTable();
|
||||||
$conditions = [sprintf('"%s"."URLSegment"', $tableName) => $URLSegment];
|
$conditions = [sprintf('"%s"."URLSegment"', $tableName) => $urlSegment];
|
||||||
if (SiteTree::config()->get('nested_urls')) {
|
if (SiteTree::config()->get('nested_urls')) {
|
||||||
$conditions[] = [sprintf('"%s"."ParentID"', $tableName) => 0];
|
$conditions[] = [sprintf('"%s"."ParentID"', $tableName) => 0];
|
||||||
}
|
}
|
||||||
|
@ -465,7 +465,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
|
|||||||
$parentIDExpr = sprintf('"%s"."ParentID"', $tableName);
|
$parentIDExpr = sprintf('"%s"."ParentID"', $tableName);
|
||||||
|
|
||||||
$link = trim(Director::makeRelative($link) ?? '', '/');
|
$link = trim(Director::makeRelative($link) ?? '', '/');
|
||||||
if (!$link) {
|
if ($link === false || $link === null || $link === '') {
|
||||||
$link = RootURLController::get_homepage_link();
|
$link = RootURLController::get_homepage_link();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1645,6 +1645,11 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function hasURLSegment(): bool
|
||||||
|
{
|
||||||
|
return $this->URLSegment !== false && $this->URLSegment !== null && $this->URLSegment !== '';
|
||||||
|
}
|
||||||
|
|
||||||
protected function onBeforeWrite()
|
protected function onBeforeWrite()
|
||||||
{
|
{
|
||||||
parent::onBeforeWrite();
|
parent::onBeforeWrite();
|
||||||
@ -1665,7 +1670,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
|
|||||||
'New {pagetype}',
|
'New {pagetype}',
|
||||||
['pagetype' => $this->i18n_singular_name()]
|
['pagetype' => $this->i18n_singular_name()]
|
||||||
));
|
));
|
||||||
if ((!$this->URLSegment || $this->URLSegment == $defaultSegment) && $this->Title) {
|
if ((!$this->hasURLSegment() || $this->URLSegment == $defaultSegment) && $this->Title) {
|
||||||
$this->URLSegment = $this->generateURLSegment($this->Title);
|
$this->URLSegment = $this->generateURLSegment($this->Title);
|
||||||
} elseif ($this->isChanged('URLSegment', 2)) {
|
} elseif ($this->isChanged('URLSegment', 2)) {
|
||||||
// Do a strict check on change level, to avoid double encoding caused by
|
// Do a strict check on change level, to avoid double encoding caused by
|
||||||
@ -1673,7 +1678,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
|
|||||||
$filter = URLSegmentFilter::create();
|
$filter = URLSegmentFilter::create();
|
||||||
$this->URLSegment = $filter->filter($this->URLSegment);
|
$this->URLSegment = $filter->filter($this->URLSegment);
|
||||||
// If after sanitising there is no URLSegment, give it a reasonable default
|
// If after sanitising there is no URLSegment, give it a reasonable default
|
||||||
if (!$this->URLSegment) {
|
if (!$this->hasURLSegment()) {
|
||||||
$this->URLSegment = "page-$this->ID";
|
$this->URLSegment = "page-$this->ID";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -131,6 +131,7 @@ class SiteTreeTest extends SapphireTest
|
|||||||
'object' => 'object',
|
'object' => 'object',
|
||||||
'controller' => 'controller',
|
'controller' => 'controller',
|
||||||
'numericonly' => '1930',
|
'numericonly' => '1930',
|
||||||
|
'numeric0' => '0',
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($expectedURLs as $fixture => $urlSegment) {
|
foreach ($expectedURLs as $fixture => $urlSegment) {
|
||||||
@ -467,6 +468,7 @@ class SiteTreeTest extends SapphireTest
|
|||||||
$about = $this->objFromFixture(SiteTree::class, 'about');
|
$about = $this->objFromFixture(SiteTree::class, 'about');
|
||||||
$staff = $this->objFromFixture(SiteTree::class, 'staff');
|
$staff = $this->objFromFixture(SiteTree::class, 'staff');
|
||||||
$product = $this->objFromFixture(SiteTree::class, 'product1');
|
$product = $this->objFromFixture(SiteTree::class, 'product1');
|
||||||
|
$numeric0 = $this->objFromFixture(SiteTree::class, 'numeric0');
|
||||||
|
|
||||||
SiteTree::config()->nested_urls = false;
|
SiteTree::config()->nested_urls = false;
|
||||||
|
|
||||||
@ -475,6 +477,7 @@ class SiteTreeTest extends SapphireTest
|
|||||||
$this->assertEquals($about->ID, SiteTree::get_by_link($about->Link(), false)->ID);
|
$this->assertEquals($about->ID, SiteTree::get_by_link($about->Link(), false)->ID);
|
||||||
$this->assertEquals($staff->ID, SiteTree::get_by_link($staff->Link(), false)->ID);
|
$this->assertEquals($staff->ID, SiteTree::get_by_link($staff->Link(), false)->ID);
|
||||||
$this->assertEquals($product->ID, SiteTree::get_by_link($product->Link(), false)->ID);
|
$this->assertEquals($product->ID, SiteTree::get_by_link($product->Link(), false)->ID);
|
||||||
|
$this->assertEquals($numeric0->ID, SiteTree::get_by_link($numeric0->Link(), false)->ID);
|
||||||
|
|
||||||
Config::modify()->set(SiteTree::class, 'nested_urls', true);
|
Config::modify()->set(SiteTree::class, 'nested_urls', true);
|
||||||
|
|
||||||
@ -483,6 +486,7 @@ class SiteTreeTest extends SapphireTest
|
|||||||
$this->assertEquals($about->ID, SiteTree::get_by_link($about->Link(), false)->ID);
|
$this->assertEquals($about->ID, SiteTree::get_by_link($about->Link(), false)->ID);
|
||||||
$this->assertEquals($staff->ID, SiteTree::get_by_link($staff->Link(), false)->ID);
|
$this->assertEquals($staff->ID, SiteTree::get_by_link($staff->Link(), false)->ID);
|
||||||
$this->assertEquals($product->ID, SiteTree::get_by_link($product->Link(), false)->ID);
|
$this->assertEquals($product->ID, SiteTree::get_by_link($product->Link(), false)->ID);
|
||||||
|
$this->assertEquals($numeric0->ID, SiteTree::get_by_link($numeric0->Link(), false)->ID);
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$staff->ID,
|
$staff->ID,
|
||||||
@ -497,6 +501,7 @@ class SiteTreeTest extends SapphireTest
|
|||||||
$about = $this->objFromFixture(SiteTree::class, 'about');
|
$about = $this->objFromFixture(SiteTree::class, 'about');
|
||||||
$staff = $this->objFromFixture(SiteTree::class, 'staff');
|
$staff = $this->objFromFixture(SiteTree::class, 'staff');
|
||||||
$product = $this->objFromFixture(SiteTree::class, 'product1');
|
$product = $this->objFromFixture(SiteTree::class, 'product1');
|
||||||
|
$numeric0 = $this->objFromFixture(SiteTree::class, 'numeric0');
|
||||||
|
|
||||||
$base = 'https://example.test/';
|
$base = 'https://example.test/';
|
||||||
$this->assertEquals($home->ID, SiteTree::get_by_link(Controller::join_links($base, '/'), false)->ID);
|
$this->assertEquals($home->ID, SiteTree::get_by_link(Controller::join_links($base, '/'), false)->ID);
|
||||||
@ -504,12 +509,14 @@ class SiteTreeTest extends SapphireTest
|
|||||||
$this->assertEquals($about->ID, SiteTree::get_by_link(Controller::join_links($base, $about->Link()), false)->ID);
|
$this->assertEquals($about->ID, SiteTree::get_by_link(Controller::join_links($base, $about->Link()), false)->ID);
|
||||||
$this->assertEquals($staff->ID, SiteTree::get_by_link(Controller::join_links($base, $staff->Link()), false)->ID);
|
$this->assertEquals($staff->ID, SiteTree::get_by_link(Controller::join_links($base, $staff->Link()), false)->ID);
|
||||||
$this->assertEquals($product->ID, SiteTree::get_by_link(Controller::join_links($base, $product->Link()), false)->ID);
|
$this->assertEquals($product->ID, SiteTree::get_by_link(Controller::join_links($base, $product->Link()), false)->ID);
|
||||||
|
$this->assertEquals($numeric0->ID, SiteTree::get_by_link(Controller::join_links($base, $numeric0->Link()), false)->ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRelativeLink()
|
public function testRelativeLink()
|
||||||
{
|
{
|
||||||
$about = $this->objFromFixture(SiteTree::class, 'about');
|
$about = $this->objFromFixture(SiteTree::class, 'about');
|
||||||
$staff = $this->objFromFixture(SiteTree::class, 'staff');
|
$staff = $this->objFromFixture(SiteTree::class, 'staff');
|
||||||
|
$numeric0 = $this->objFromFixture(SiteTree::class, 'numeric0');
|
||||||
|
|
||||||
Config::modify()->set(SiteTree::class, 'nested_urls', true);
|
Config::modify()->set(SiteTree::class, 'nested_urls', true);
|
||||||
|
|
||||||
@ -523,6 +530,7 @@ class SiteTreeTest extends SapphireTest
|
|||||||
$staff->RelativeLink(),
|
$staff->RelativeLink(),
|
||||||
'Matches URLSegment plus parent on second level without parameters'
|
'Matches URLSegment plus parent on second level without parameters'
|
||||||
);
|
);
|
||||||
|
$this->assertEquals('0/', $numeric0->RelativeLink(), 'Matches URLSegment for segment = 0');
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'about-us/edit',
|
'about-us/edit',
|
||||||
$about->RelativeLink('edit'),
|
$about->RelativeLink('edit'),
|
||||||
|
@ -112,6 +112,9 @@ SilverStripe\CMS\Model\SiteTree:
|
|||||||
breadcrumbs5:
|
breadcrumbs5:
|
||||||
Title: 'Breadcrumbs 5'
|
Title: 'Breadcrumbs 5'
|
||||||
Parent: =>SilverStripe\CMS\Model\SiteTree.breadcrumbs4
|
Parent: =>SilverStripe\CMS\Model\SiteTree.breadcrumbs4
|
||||||
|
numeric0:
|
||||||
|
Title: 'urlsegment is 0'
|
||||||
|
URLSegment: '0'
|
||||||
|
|
||||||
SilverStripe\CMS\Tests\Model\SiteTreeTest_Conflicted:
|
SilverStripe\CMS\Tests\Model\SiteTreeTest_Conflicted:
|
||||||
parent:
|
parent:
|
||||||
|
Loading…
Reference in New Issue
Block a user