本文整理匯總了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');
}