getAllowedChildren()) { if($v instanceof BedrockSetting) $v = $v->toArray(); $statics['allowed_children'] = $v; } $statics['default_child'] = $settings->getDefaultChild(); $statics['default_parent'] = $settings->getDefaultParent(); $statics['can_be_root'] = $settings->getCanBeRoot(); $statics['need_permission'] = $settings->getNeedPermission(); $statics['hide_ancestor'] = $settings->getHideAncestor(); $statics['default_sort'] = $settings->getDefaultSort(); $statics['can_create'] = $settings->getCanCreate(); $statics['icon'] = $settings->getIcon(); if($v = $settings->getEnforceParentChild()) { if(class_exists($v)) { Object::set_static($v, 'can_be_root', false); $statics['default_child'] = $v; $statics['allowed_children'] = array($v); } } } $r_statics = $statics; $r_statics['belongs_many_many'] = Object::get_static($class, 'belongs_many_many'); $r_statics = print_r($r_statics, true); Bedrock::message("Statics for class $class: $r_statics",""); return $statics; } /** * Based on the class configuration, build a CMS interface for this page, respecting * all of the database fields and related objects. * * @param FieldSet $fieldset A reference to a fieldset that has already been create * by this class */ public function updateCMSFields(&$fieldset) { if(!$this->getClassSettings()) return; $class = $this->owner->class; // Is this a subclass of a page already decorated? If so, get its fields. $parent = get_parent_class($this->owner->class); while(!in_array($parent, array('DataObject','SiteTree'))) { if(Object::has_extension($parent, "BedrockSiteTree") || Object::has_extension($parent, "BedrockPage")) { $SNG = singleton($parent); $SNG->defineMethods(); // Force the ID so relations don't get messed up. $SNG->ID = $this->owner->ID; $SNG->updateCMSFields(&$fieldset); } $parent = get_parent_class($parent); } if($fields = $this->getClassSettings()->getFields()) { foreach($fields as $field) { $field->setControllerClass($class); $form_field = $field->getFormField(); if($t = $field->getTab()) { $fieldset->addFieldToTab($field->getTab(), $form_field, $field->getBefore()); } else { $fieldset->push($form_field); } } } if($components = $this->getClassSettings()->getComponents()) { foreach($components as $component) { if($type = $component->getType()) { $component->setControllerClass($class); $interface = $component->buildInterface($this->owner); if($interface) { $fieldset->addFieldToTab($component->getTab(), $interface); } } } } parent::updateCMSFields($fieldset); } /** * Override the canCreate() method to check the AllowedInstances property. * Note: this method always returns TRUE for admin users. * * @return boolean */ public function canCreate() { if($settings = $this->getClassSettings()) { if($instances = $settings->getAllowedInstances()) { if($set = DataObject::get($this->owner->class)) return $set->Count() < $instances; } } } /** * A useful method for getting a single record from the database. * Ex. <% control Singleton(HomePage) %> * * @param string $class The class to fetch from the database * @return DataObject */ public function Singleton($class) { if(class_exists($class)) { return DataObject::get_one($class); } return false; } /** * Using {@link Singleton()}, get a link to a single record in the database * * @param string $class The class of page to link to * @return string */ public function SingleLink($class) { if($o = $this->Singleton($class)) return $o->Link(); return false; } /** * A useful method for getting an all-inclusive set of records at the template level. * Ex. <% control Set(Objects) %> * * @param string $class The type of object to fetch * @return DataObjectSet */ public function Set($class) { return DataObject::get($class); } }