Skip to content

Commit

Permalink
FIX Subsites virtual pages now allow you to re-save them when used in…
Browse files Browse the repository at this point in the history
… conjunction with silverstripe-fluent
  • Loading branch information
robbieaverill committed May 31, 2019
1 parent d1fc84d commit 1f51fcd
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions src/Pages/SubsitesVirtualPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use SilverStripe\Control\Controller;
use SilverStripe\Core\Config\Config;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\LabelField;
use SilverStripe\Forms\LiteralField;
use SilverStripe\Forms\TextareaField;
use SilverStripe\Forms\TextField;
Expand Down Expand Up @@ -223,33 +222,25 @@ public function validURLSegment()
{
$isValid = parent::validURLSegment();

$filters = [
'URLSegment' => $this->URLSegment,
];

// Veto the validation rules if its false. In this case, some logic
// needs to be duplicated from parent to find out the exact reason the validation failed.
if (!$isValid) {
$IDFilter = $this->ID ? "AND \"SiteTree\".\"ID\" <> $this->ID" : null;
$parentFilter = null;
// Exclude the current page from the filter
$filters['ID:not'] = $this->ID;

if (Config::inst()->get(SiteTree::class, 'nested_urls')) {
if ($this->ParentID) {
$parentFilter = " AND \"SiteTree\".\"ParentID\" = $this->ParentID";
} else {
$parentFilter = ' AND "SiteTree"."ParentID" = 0';
}
$filters['ParentID'] = $this->ParentID ?: 0;
}

$origDisableSubsiteFilter = Subsite::$disable_subsite_filter;
Subsite::$disable_subsite_filter = true;
$existingPage = DataObject::get_one(
SiteTree::class,
"\"URLSegment\" = '$this->URLSegment' $IDFilter $parentFilter",
false // disable cache, it doesn't include subsite status in the key
);
Subsite::$disable_subsite_filter = $origDisableSubsiteFilter;
$existingPageInSubsite = DataObject::get_one(
SiteTree::class,
"\"URLSegment\" = '$this->URLSegment' $IDFilter $parentFilter",
false // disable cache, it doesn't include subsite status in the key
);
Subsite::disable_subsite_filter();
$existingPage = SiteTree::get()->filter($filters)->first();
Subsite::disable_subsite_filter($origDisableSubsiteFilter);
$existingPageInSubsite = SiteTree::get()->filter($filters)->first();

// If URL has been vetoed because of an existing page,
// be more specific and allow same URLSegments in different subsites
Expand Down

0 comments on commit 1f51fcd

Please sign in to comment.