Merge pull request #1929 from robbieaverill/pulls/4.0/replace-stat-usage

Replace use of Configurable stat() with config()->get(), will be deprecated in future
This commit is contained in:
Loz Calver 2017-08-23 10:26:45 +01:00 committed by GitHub
commit 9a9b4e205c
6 changed files with 29 additions and 29 deletions

View File

@ -268,7 +268,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
{ {
$link = Controller::join_links( $link = Controller::join_links(
AdminRootController::admin_url(), AdminRootController::admin_url(),
$this->stat('url_segment'), // in case we want to change the segment $this->config()->get('url_segment'), // in case we want to change the segment
'/', // trailing slash needed if $action is null! '/', // trailing slash needed if $action is null!
"$action" "$action"
); );
@ -439,7 +439,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
// Pre-cache sitetree version numbers for querying efficiency // Pre-cache sitetree version numbers for querying efficiency
Versioned::prepopulate_versionnumber_cache(SiteTree::class, Versioned::DRAFT); Versioned::prepopulate_versionnumber_cache(SiteTree::class, Versioned::DRAFT);
Versioned::prepopulate_versionnumber_cache(SiteTree::class, Versioned::LIVE); Versioned::prepopulate_versionnumber_cache(SiteTree::class, Versioned::LIVE);
$html = $this->getSiteTreeFor($this->stat('tree_class')); $html = $this->getSiteTreeFor($this->config()->get('tree_class'));
$this->extend('updateSiteTreeAsUL', $html); $this->extend('updateSiteTreeAsUL', $html);
@ -583,7 +583,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
public function getsubtree($request) public function getsubtree($request)
{ {
$html = $this->getSiteTreeFor( $html = $this->getSiteTreeFor(
$this->stat('tree_class'), $this->config()->get('tree_class'),
$request->getVar('ID'), $request->getVar('ID'),
null, null,
null, null,
@ -632,7 +632,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
// TODO: These methods should really be in hierarchy - for a start it assumes Sort exists // TODO: These methods should really be in hierarchy - for a start it assumes Sort exists
$prev = null; $prev = null;
$className = $this->stat('tree_class'); $className = $this->config()->get('tree_class');
$next = DataObject::get($className) $next = DataObject::get($className)
->filter('ParentID', $record->ParentID) ->filter('ParentID', $record->ParentID)
->filter('Sort:GreaterThan', $record->Sort) ->filter('Sort:GreaterThan', $record->Sort)
@ -694,7 +694,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
); );
} }
$className = $this->stat('tree_class'); $className = $this->config()->get('tree_class');
$id = $request->requestVar('ID'); $id = $request->requestVar('ID');
$parentID = $request->requestVar('ParentID'); $parentID = $request->requestVar('ParentID');
if (!is_numeric($id) || !is_numeric($parentID)) { if (!is_numeric($id) || !is_numeric($parentID)) {
@ -980,8 +980,8 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
); );
// Check if can be created at the root // Check if can be created at the root
$needsPerm = $obj->stat('need_permission'); $needsPerm = $obj->config()->get('need_permission');
if (!$obj->stat('can_be_root') if (!$obj->config()->get('can_be_root')
|| (!array_key_exists($class, $cacheCanCreate) || !$cacheCanCreate[$class]) || (!array_key_exists($class, $cacheCanCreate) || !$cacheCanCreate[$class])
|| ($needsPerm && !$this->can($needsPerm)) || ($needsPerm && !$this->can($needsPerm))
) { ) {
@ -1029,7 +1029,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
} }
// skip this type if it is restricted // skip this type if it is restricted
if ($instance->stat('need_permission') && !$this->can(singleton($class)->stat('need_permission'))) { if ($instance->config()->get('need_permission') && !$this->can(singleton($class)->config()->get('need_permission'))) {
continue; continue;
} }
@ -1041,7 +1041,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
'AddAction' => $singularName, 'AddAction' => $singularName,
'Description' => $description, 'Description' => $description,
// TODO Sprite support // TODO Sprite support
'IconURL' => $instance->stat('icon'), 'IconURL' => $instance->config()->get('icon'),
'Title' => $singularName, 'Title' => $singularName,
))); )));
} }
@ -1063,7 +1063,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
if (!$id) { if (!$id) {
return null; return null;
} }
$treeClass = $this->stat('tree_class'); $treeClass = $this->config()->get('tree_class');
if ($id instanceof $treeClass) { if ($id instanceof $treeClass) {
return $id; return $id;
} }
@ -1423,7 +1423,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
if ($filter = $this->getQueryFilter($params)) { if ($filter = $this->getQueryFilter($params)) {
return $filter->getFilteredPages(); return $filter->getFilteredPages();
} else { } else {
$list = DataList::create($this->stat('tree_class')); $list = DataList::create($this->config()->get('tree_class'));
$parentID = is_numeric($parentID) ? $parentID : 0; $parentID = is_numeric($parentID) ? $parentID : 0;
return $list->filter("ParentID", $parentID); return $list->filter("ParentID", $parentID);
} }
@ -1555,7 +1555,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
*/ */
public function save($data, $form) public function save($data, $form)
{ {
$className = $this->stat('tree_class'); $className = $this->config()->get('tree_class');
// Existing or new record? // Existing or new record?
$id = $data['ID']; $id = $data['ID'];
@ -1631,7 +1631,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
*/ */
public function getNewItem($id, $setID = true) public function getNewItem($id, $setID = true)
{ {
$parentClass = $this->stat('tree_class'); $parentClass = $this->config()->get('tree_class');
list(, $className, $parentID) = array_pad(explode('-', $id), 3, null); list(, $className, $parentID) = array_pad(explode('-', $id), 3, null);
if (!is_a($className, $parentClass, true)) { if (!is_a($className, $parentClass, true)) {
@ -1823,7 +1823,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
public function unpublish($data, $form) public function unpublish($data, $form)
{ {
$className = $this->stat('tree_class'); $className = $this->config()->get('tree_class');
/** @var SiteTree $record */ /** @var SiteTree $record */
$record = DataObject::get_by_id($className, $data['ID']); $record = DataObject::get_by_id($className, $data['ID']);
@ -1870,7 +1870,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
$version = (isset($data['Version'])) ? (int) $data['Version'] : null; $version = (isset($data['Version'])) ? (int) $data['Version'] : null;
/** @var DataObject|Versioned $record */ /** @var DataObject|Versioned $record */
$record = DataObject::get_by_id($this->stat('tree_class'), $id); $record = DataObject::get_by_id($this->config()->get('tree_class'), $id);
if ($record && !$record->canEdit()) { if ($record && !$record->canEdit()) {
return Security::permissionFailure($this); return Security::permissionFailure($this);
} }

View File

@ -31,7 +31,7 @@ class LeftAndMainPageIconsExtension extends Extension
$classes = ClassInfo::subclassesFor('SilverStripe\\CMS\\Model\\SiteTree'); $classes = ClassInfo::subclassesFor('SilverStripe\\CMS\\Model\\SiteTree');
foreach ($classes as $class) { foreach ($classes as $class) {
$obj = singleton($class); $obj = singleton($class);
$iconSpec = $obj->stat('icon'); $iconSpec = $obj->config()->get('icon');
if (!$iconSpec) { if (!$iconSpec) {
continue; continue;

View File

@ -88,7 +88,7 @@ abstract class SilverStripeNavigatorItem extends ViewableData
*/ */
public function getPriority() public function getPriority()
{ {
return $this->stat('priority'); return $this->config()->get('priority');
} }
/** /**

View File

@ -452,7 +452,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
$instance = singleton($class); $instance = singleton($class);
// do any of the progeny want to hide an ancestor? // do any of the progeny want to hide an ancestor?
if ($ancestor_to_hide = $instance->stat('hide_ancestor')) { if ($ancestor_to_hide = $instance->config()->get('hide_ancestor')) {
// note for killing later // note for killing later
$kill_ancestors[] = $ancestor_to_hide; $kill_ancestors[] = $ancestor_to_hide;
} }
@ -990,7 +990,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
return true; return true;
} }
return $this->canEdit($member) && $this->stat('allowed_children') !== 'none'; return $this->canEdit($member) && $this->config()->get('allowed_children') !== 'none';
} }
/** /**
@ -1522,7 +1522,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
} }
// "Can be root" validation // "Can be root" validation
if (!$this->stat('can_be_root') && !$this->ParentID) { if (!$this->config()->get('can_be_root') && !$this->ParentID) {
$result->addError( $result->addError(
_t( _t(
'SilverStripe\\CMS\\Model\\SiteTree.PageTypNotAllowedOnRoot', 'SilverStripe\\CMS\\Model\\SiteTree.PageTypNotAllowedOnRoot',
@ -2419,7 +2419,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
} }
} }
if ($perms = $instance->stat('need_permission')) { if ($perms = $instance->config()->get('need_permission')) {
if (!$this->can($perms)) { if (!$this->can($perms)) {
continue; continue;
} }
@ -2498,7 +2498,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
*/ */
public function defaultChild() public function defaultChild()
{ {
$default = $this->stat('default_child'); $default = $this->config()->get('default_child');
$allowed = $this->allowedChildren(); $allowed = $this->allowedChildren();
if ($allowed) { if ($allowed) {
if (!$default || !in_array($default, $allowed)) { if (!$default || !in_array($default, $allowed)) {
@ -2516,7 +2516,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
*/ */
public function defaultParent() public function defaultParent()
{ {
return $this->stat('default_parent'); return $this->config()->get('default_parent');
} }
/** /**
@ -2802,7 +2802,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
{ {
$base = in_array(static::class, [Page::class, self::class]); $base = in_array(static::class, [Page::class, self::class]);
if ($base) { if ($base) {
return $this->stat('base_singular_name'); return $this->config()->get('base_singular_name');
} }
return parent::singular_name(); return parent::singular_name();
} }
@ -2816,7 +2816,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
{ {
$base = in_array(static::class, [Page::class, self::class]); $base = in_array(static::class, [Page::class, self::class]);
if ($base) { if ($base) {
return $this->stat('base_plural_name'); return $this->config()->get('base_plural_name');
} }
return parent::plural_name(); return parent::plural_name();
} }
@ -2830,9 +2830,9 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
{ {
$base = in_array(static::class, [Page::class, self::class]); $base = in_array(static::class, [Page::class, self::class]);
if ($base) { if ($base) {
return $this->stat('base_description'); return $this->config()->get('base_description');
} }
return $this->stat('description'); return $this->config()->get('description');
} }
/** /**

View File

@ -335,7 +335,7 @@ class VirtualPage extends Page
// "Can be root" validation // "Can be root" validation
$orig = $this->CopyContentFrom(); $orig = $this->CopyContentFrom();
if ($orig && $orig->exists() && !$orig->stat('can_be_root') && !$this->ParentID) { if ($orig && $orig->exists() && !$orig->config()->get('can_be_root') && !$this->ParentID) {
$result->addError( $result->addError(
_t( _t(
'SilverStripe\\CMS\\Model\\VirtualPage.PageTypNotAllowedOnRoot', 'SilverStripe\\CMS\\Model\\VirtualPage.PageTypNotAllowedOnRoot',

View File

@ -174,7 +174,7 @@ class CMSMainTest extends FunctionalTest
if ($page instanceof TestOnly) { if ($page instanceof TestOnly) {
continue; continue;
} }
if (!$page->stat('can_be_root')) { if (!$page->config()->get('can_be_root')) {
continue; continue;
} }