Merge pull request #1713 from hailwood/patch-1

Clean up code for url-segment checks
This commit is contained in:
Damian Mooyman 2017-01-16 17:44:12 +13:00 committed by GitHub
commit 540a80766d

View File

@ -1719,20 +1719,18 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
$filter['"SiteTree"."ParentID"'] = $this->ParentID ? $this->ParentID : 0; $filter['"SiteTree"."ParentID"'] = $this->ParentID ? $this->ParentID : 0;
} }
$votes = array_filter( // If any of the extensions return `0` consider the segment invalid
$extensionResponses = array_filter(
(array)$this->extend('augmentValidURLSegment'), (array)$this->extend('augmentValidURLSegment'),
function($v) {return !is_null($v);} function($response) {return !is_null($response);}
); );
if($votes) { if($extensionResponses) {
return min($votes); return min($extensionResponses);
} }
// Check existence // Check existence
$existingPage = DataObject::get_one(self::class, $filter); return !DataObject::get(self::class, $filter)->exists();
if ($existingPage) return false; }
return !($existingPage);
}
/** /**
* Generate a URL segment based on the title provided. * Generate a URL segment based on the title provided.