Default priority is now based on a page's depth in the site tree, but can be overwritten.

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@44513 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Hayden Smith 2007-11-08 04:23:33 +00:00
parent 491efc6d75
commit c32493a550

View File

@ -123,8 +123,6 @@ class SiteTree extends DataObject {
"ShowInSearch" => 1,
"Status" => "New page",
"CanCreateChildren" => array(10),
"Priority" => 0.5,
"Viewers" => "Anyone",
"Editors" => "LoggedInUsers"
);
@ -894,6 +892,19 @@ class SiteTree extends DataObject {
self::$cms_additions[] = $function;
}
/**
* The default value of the priority field depends on the depth of the page in
* the site tree, so it must be calculated dynamically.
*/
function getPriority() {
if($this->getField('Priority') === null) {
$parentStack = $this->parentStack();
$numParents = is_array($parentStack) ? count($parentStack) - 1: 0;
return max(0.1, 1.0 - ($numParents / 10));
}
return $this->getField('Priority');
}
/**
* Returns a FieldSet with which to create the CMS editing form.
@ -973,7 +984,7 @@ class SiteTree extends DataObject {
$pagePriorities = array(
'0' => _t('SiteTree.PRIORITYNOTINDEXED', "Not indexed"),
'0.0' => _t('SiteTree.PRIORITYNOTINDEXED', "Not indexed"),
'1.0' => '1 - ' . _t('SiteTree.PRIORITYMOSTIMPORTANT', "Most important"),
'0.9' => '2',
'0.8' => '3',
@ -985,7 +996,7 @@ class SiteTree extends DataObject {
'0.2' => '9',
'0.1' => '10 - ' . _t('SiteTree.PRIORITYLEASTIMPORTANT', "Least important")
);
// Lay out the fields
$fields = new FieldSet(
new TabSet("Root",