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;
 }
 /**
  * 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;
 }
 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
0
 /**
  * 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');
 }