本文整理汇总了PHP中SiteTree::allowedChildren方法的典型用法代码示例。如果您正苦于以下问题:PHP SiteTree::allowedChildren方法的具体用法?PHP SiteTree::allowedChildren怎么用?PHP SiteTree::allowedChildren使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SiteTree
的用法示例。
在下文中一共展示了SiteTree::allowedChildren方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getAllowedChildren
public function getAllowedChildren(SiteTree $parent)
{
$allowedChildren = $parent->allowedChildren();
if (empty($allowedChildren)) {
return array();
}
$children = array();
foreach ($allowedChildren as $class) {
if (Config::inst()->get($class, "show_in_sitetree") === false) {
$children[$class] = Injector::inst()->create($class)->i18n_singular_name();
}
}
return $children;
}
示例2: getAllowedChildren
/**
* Determine the list of classnames and titles allowed for a given parent object
*
* @param SiteTree $parent
* @return boolean
*/
public function getAllowedChildren(SiteTree $parent = null)
{
if (!$parent || !$parent->canAddChildren()) {
return array();
}
$allowedChildren = $parent->allowedChildren();
$children = array();
foreach ($allowedChildren as $class) {
if (Config::inst()->get($class, "show_in_sitetree") === false) {
$instance = Injector::inst()->get($class);
// Note: Second argument to SiteTree::canCreate will support inherited permissions
// post 3.1.12, and will default to the old permission model in 3.1.11 or below
// See http://docs.silverstripe.org/en/changelogs/3.1.11
if ($instance->canCreate(null, array('Parent' => $parent))) {
$children[$class] = $instance->i18n_singular_name();
}
}
}
return $children;
}
示例3: testAllowedChildren
public function testAllowedChildren()
{
$page = new SiteTree();
$this->assertContains('VirtualPage', $page->allowedChildren(), 'Includes core subclasses by default');
$classA = new SiteTreeTest_ClassA();
$this->assertEquals(array('SiteTreeTest_ClassB'), $classA->allowedChildren(), 'Direct setting of allowed children');
$classB = new SiteTreeTest_ClassB();
$this->assertEquals(array('SiteTreeTest_ClassC', 'SiteTreeTest_ClassCext'), $classB->allowedChildren(), 'Includes subclasses');
$classD = new SiteTreeTest_ClassD();
$this->assertEquals(array('SiteTreeTest_ClassC'), $classD->allowedChildren(), 'Excludes subclasses if class is prefixed by an asterisk');
$classC = new SiteTreeTest_ClassC();
$this->assertEquals(array(), $classC->allowedChildren(), 'Null setting');
}
示例4: testAllowedChildrenContainsCoreSubclassesButNotHiddenClass
/**
* Tests that core subclasses of SiteTree are included in allowedChildren() by default, but not instances of
* HiddenClass
*/
public function testAllowedChildrenContainsCoreSubclassesButNotHiddenClass()
{
$page = new SiteTree();
$allowedChildren = $page->allowedChildren();
$this->assertContains('VirtualPage', $allowedChildren, 'Includes core subclasses by default');
$this->assertNotContains('SiteTreeTest_ClassE', $allowedChildren, 'HiddenClass instances should not be returned');
}