function __construct($controller, $name, $sourceClass, $fieldList = null, $detailFormFields = null, $sourceFilter = "", $sourceSort = "", $sourceJoin = "") { parent::__construct($controller, $name, $sourceClass, $fieldList, $detailFormFields, $sourceFilter, $sourceSort, $sourceJoin); //Sort by heirarchy, depending on number of parents indent $classes = array_reverse(ClassInfo::ancestry($this->controllerClass())); foreach ($classes as $class) { $singleton = singleton($class); $manyManyRelations = $singleton->uninherited('many_many', true); if (isset($manyManyRelations) && array_key_exists($this->name, $manyManyRelations)) { $this->manyManyParentClass = $class; $this->manyManyTable = $class . '_' . $this->name; break; } $belongsManyManyRelations = $singleton->uninherited('belongs_many_many', true); if (isset($belongsManyManyRelations) && array_key_exists($this->name, $belongsManyManyRelations)) { $singleton = singleton($belongsManyManyRelations[$this->name]); $manyManyRelations = $singleton->uninherited('many_many', true); $this->manyManyParentClass = $class; $relation = array_flip($manyManyRelations); $this->manyManyTable = $belongsManyManyRelations[$this->name] . '_' . $relation[$class]; break; } } $tableClasses = ClassInfo::dataClassesFor($this->sourceClass); $source = array_shift($tableClasses); $sourceField = $this->sourceClass; if ($this->manyManyParentClass == $sourceField) { $sourceField = 'Child'; } $parentID = $this->controller->ID; $this->sourceJoin .= " LEFT JOIN \"{$this->manyManyTable}\" ON (\"{$source}\".\"ID\" = \"{$this->manyManyTable}\".\"{$sourceField}ID\" AND \"{$this->manyManyTable}\".\"{$this->manyManyParentClass}ID\" = '{$parentID}')"; $this->joinField = 'Checked'; }
public function bootstrapify() { $inline_fields = Config::inst()->get('BootstrapForm', 'inline_fields'); foreach ($this->owner as $f) { if (isset($this->ignores[$f->getName()])) { continue; } if ($f instanceof CompositeField) { $f->getChildren()->bootstrapify(); continue; } if (!in_array($f->class, $inline_fields)) { $f->addExtraClass('form-control'); } $template = "Bootstrap{$f->class}_holder"; if (SSViewer::hasTemplate($template)) { $f->setFieldHolderTemplate($template); } else { $f->setFieldHolderTemplate("BootstrapFieldHolder"); } foreach (array_reverse(ClassInfo::ancestry($f)) as $className) { $bootstrapCandidate = "Bootstrap{$className}"; $nativeCandidate = $className; if (SSViewer::hasTemplate($bootstrapCandidate)) { $f->setTemplate($bootstrapCandidate); break; } elseif (SSViewer::hasTemplate($nativeCandidate)) { $f->setTemplate($nativeCandidate); break; } } } return $this->owner; }
function __construct($controller, $name, $sourceClass, $fieldList = null, $detailFormFields = null, $sourceFilter = "", $sourceSort = "", $sourceJoin = "") { Deprecation::notice('3.0', 'Use GridField with GridFieldConfig_RelationEditor'); parent::__construct($controller, $name, $sourceClass, $fieldList, $detailFormFields, $sourceFilter, $sourceSort, $sourceJoin); $classes = array_reverse(ClassInfo::ancestry($this->controllerClass())); foreach($classes as $class) { $singleton = singleton($class); $manyManyRelations = $singleton->uninherited('many_many', true); if(isset($manyManyRelations) && array_key_exists($this->name, $manyManyRelations)) { $this->manyManyParentClass = $class; $manyManyTable = $class . '_' . $this->name; break; } $belongsManyManyRelations = $singleton->uninherited( 'belongs_many_many', true ); if( isset( $belongsManyManyRelations ) && array_key_exists( $this->name, $belongsManyManyRelations ) ) { $this->manyManyParentClass = $class; $manyManyTable = $belongsManyManyRelations[$this->name] . '_' . $this->name; break; } } $tableClasses = ClassInfo::dataClassesFor($this->sourceClass); $source = array_shift($tableClasses); $sourceField = $this->sourceClass; if($this->manyManyParentClass == $sourceField) $sourceField = 'Child'; $parentID = $this->controller->ID; $this->sourceJoin .= " LEFT JOIN \"$manyManyTable\" ON (\"$source\".\"ID\" = \"$manyManyTable\".\"{$sourceField}ID\" AND \"{$this->manyManyParentClass}ID\" = '$parentID')"; $this->joinField = 'Checked'; }
/** * Most of the code below was copied from ManyManyComplexTableField. * Painful, but necessary, until PHP supports multiple inheritance. */ function __construct($controller, $name, $sourceClass, $fieldList, $detailFormFields = null, $sourceFilter = "", $sourceSort = "Created DESC", $sourceJoin = "") { parent::__construct($controller, $name, $sourceClass, $fieldList, $detailFormFields, $sourceFilter, $sourceSort, $sourceJoin); $manyManyTable = false; $classes = array_reverse(ClassInfo::ancestry($this->controllerClass())); foreach ($classes as $class) { if ($class != "Object") { $singleton = singleton($class); $manyManyRelations = $singleton->uninherited('many_many', true); if (isset($manyManyRelations) && array_key_exists($this->name, $manyManyRelations)) { $this->manyManyParentClass = $class; $manyManyTable = $class . '_' . $this->name; break; } $belongsManyManyRelations = $singleton->uninherited('belongs_many_many', true); if (isset($belongsManyManyRelations) && array_key_exists($this->name, $belongsManyManyRelations)) { $this->manyManyParentClass = $class; $manyManyTable = $belongsManyManyRelations[$this->name] . '_' . $this->name; break; } } } if (!$manyManyTable) { user_error("I could not find the relation {$this}-name in " . $this->controllerClass() . " or any of its ancestors.", E_USER_WARNING); } $tableClasses = ClassInfo::dataClassesFor($this->sourceClass); $source = array_shift($tableClasses); $sourceField = $this->sourceClass; if ($this->manyManyParentClass == $sourceField) { $sourceField = 'Child'; } $parentID = $this->controller->ID; $this->sourceJoin .= " LEFT JOIN `{$manyManyTable}` ON (`{$source}`.`ID` = `{$sourceField}ID` AND `{$this->manyManyParentClass}ID` = '{$parentID}')"; $this->joinField = 'Checked'; }
function __construct($controller, $name, $sourceClass, $fieldList, $detailFormFields = null, $sourceFilter = "", $sourceSort = "", $sourceJoin = "") { parent::__construct($controller, $name, $sourceClass, $fieldList, $detailFormFields, $sourceFilter, $sourceSort, $sourceJoin); $classes = array_reverse(ClassInfo::ancestry($this->controller->ClassName)); foreach ($classes as $class) { $singleton = singleton($class); $manyManyRelations = $singleton->uninherited('many_many', true); if (isset($manyManyRelations) && array_key_exists($this->name, $manyManyRelations)) { $this->manyManyParentClass = $class; $manyManyTable = $class . '_' . $this->name; break; } $belongsManyManyRelations = $singleton->uninherited('belongs_many_many', true); if (isset($belongsManyManyRelations) && array_key_exists($this->name, $belongsManyManyRelations)) { $this->manyManyParentClass = $class; $manyManyTable = $belongsManyManyRelations[$this->name] . '_' . $this->name; break; } } $source = $this->sourceClass; $sourceField = $this->sourceClass; if ($this->manyManyParentClass == $source) { $sourceField = 'Child'; } $parentID = $this->controller->ID; $this->sourceJoin .= " LEFT JOIN `{$manyManyTable}` ON (`{$source}`.`ID` = `{$sourceField}ID` AND `{$this->manyManyParentClass}ID` = '{$parentID}')"; $this->joinField = 'Checked'; }
/** * Description * @return string */ protected function determineFolderName() { // Grab paths $paths = Config::inst()->get(__CLASS__, 'upload_paths'); // Grab ancestry from top-down $className = get_class($this->record); $classes = array_reverse(ClassInfo::ancestry($className)); $path = $className; // Loop over ancestry and break out if we have a match foreach ($classes as $class) { if (array_key_exists($class, $paths)) { $path = $paths[$class]; break; } } // If there are any parameters which require matching, search for them $matches = array(); preg_match_all('/\\$[a-zA-Z0-9]+?/U', $path, $matches); // Replace with field values foreach ($matches[0] as $match) { $field = str_replace("\$", "", $match); $value = FileNameFilter::create()->filter($this->record->getField($field)); $path = str_replace($match, $value, $path); } $this->folderName = $path; return $path; }
/** * Get the appropriate {@link CatalogueProductController} or * {@link CatalogueProductController} for handling the relevent * object. * * @param $object Either Product or Category object * @param string $action * @return CatalogueController */ protected static function controller_for($object, $action = null) { if ($object->class == 'CatalogueProduct') { $controller = "CatalogueProductController"; } elseif ($object->class == 'CatalogueCategory') { $controller = "CatalogueCategoryController"; } else { $ancestry = ClassInfo::ancestry($object->class); while ($class = array_pop($ancestry)) { if (class_exists($class . "_Controller")) { break; } } // Find the controller we need, or revert to a default if ($class !== null) { $controller = "{$class}_Controller"; } elseif (ClassInfo::baseDataClass($object->class) == "CatalogueProduct") { $controller = "CatalogueProductController"; } elseif (ClassInfo::baseDataClass($object->class) == "CatalogueCategory") { $controller = "CatalogueCategoryController"; } } if ($action && class_exists($controller . '_' . ucfirst($action))) { $controller = $controller . '_' . ucfirst($action); } return class_exists($controller) ? Injector::inst()->create($controller, $object) : $object; }
protected function foreignIDFilter($id = null) { if ($id === null) { $id = $this->getForeignID(); } $class = $this->dataClass; $class_type = $class::create(); $has_field = !is_null($class_type->hasOwnTableDatabaseField($this->foreignKey)); if (!$has_field) { foreach (ClassInfo::ancestry($class_type) as $parent_class) { if (in_array($parent_class, array('ViewableData', 'Object', 'DataObject'))) { continue; } $class_type_parent = $parent_class::create(); $has_field = !is_null($class_type_parent->hasOwnTableDatabaseField($this->foreignKey)); if ($has_field) { $class = $parent_class; break; } } } // Apply relation filter if (is_array($id)) { return "\"{$class}\".\"{$this->foreignKey}\" IN ('" . implode("', '", array_map('Convert::raw2sql', $id)) . "')"; } else { if ($id !== null) { return "\"{$class}\".\"{$this->foreignKey}\" = '" . Convert::raw2sql($id) . "'"; } } }
public function locateConfigFor($name) { // Check direct or cached result $config = $this->configFor($name); if ($config !== null) { return $config; } // do parent lookup if it's a class if (class_exists($name)) { $parents = array_reverse(array_keys(ClassInfo::ancestry($name))); array_shift($parents); foreach ($parents as $parent) { // have we already got for this? $config = $this->configFor($parent); if ($config !== null) { // Cache this result $this->configs[$name] = $config; return $config; } } } // there is no parent config, so we'll record that as false so we don't do the expensive // lookup through parents again $this->configs[$name] = false; }
public function locateConfigFor($name) { if (isset($this->configs[$name])) { return $this->configs[$name]; } $config = Config::inst()->get('Injector', $name); if ($config) { $this->configs[$name] = $config; return $config; } // do parent lookup if it's a class if (class_exists($name)) { $parents = array_reverse(array_keys(ClassInfo::ancestry($name))); array_shift($parents); foreach ($parents as $parent) { // have we already got for this? if (isset($this->configs[$parent])) { return $this->configs[$parent]; } $config = Config::inst()->get('Injector', $parent); if ($config) { $this->configs[$name] = $config; return $config; } else { $this->configs[$parent] = false; } } // there is no parent config, so we'll record that as false so we don't do the expensive // lookup through parents again $this->configs[$name] = false; } }
/** * Changes the templates of all the {@link FormField} * objects in a given {@link FieldList} object to those * that work the Bootstrap framework * * @param FieldList $fields */ public static function apply_bootstrap_to_fieldlist($fields) { foreach ($fields as $f) { // If we have a Tabset, bootstrapify all Tabs if ($f instanceof TabSet) { self::apply_bootstrap_to_fieldlist($f->Tabs()); } // If we have a Tab, bootstrapify all its Fields if ($f instanceof Tab) { self::apply_bootstrap_to_fieldlist($f->Fields()); } $template = "Bootstrap{$f->class}_holder"; if (SSViewer::hasTemplate($template)) { $f->setFieldHolderTemplate($template); } else { $f->setFieldHolderTemplate("BootstrapFieldHolder"); } foreach (array_reverse(ClassInfo::ancestry($f)) as $className) { $bootstrapCandidate = "Bootstrap{$className}"; $nativeCandidate = $className; if (SSViewer::hasTemplate($bootstrapCandidate)) { $f->setTemplate($bootstrapCandidate); break; } elseif (SSViewer::hasTemplate($nativeCandidate)) { $f->setTemplate($nativeCandidate); break; } } } }
public function transform(FormField $field) { // Look for a performXXTransformation() method on the field itself. // performReadonlyTransformation() is a pretty commonly applied method. // Otherwise, look for a transformXXXField() method on this object. // This is more commonly done in custom transformations // We iterate through each array simultaneously, looking at [0] of both, then [1] of both. // This provides a more natural failover scheme. $transNames = array_reverse(array_values(ClassInfo::ancestry($this->class))); $fieldClasses = array_reverse(array_values(ClassInfo::ancestry($field->class))); $len = max(sizeof($transNames), sizeof($fieldClasses)); for ($i = 0; $i < $len; $i++) { // This is lets fieldClasses be longer than transNames if ($transName = $transNames[$i]) { if ($field->hasMethod('perform' . $transName)) { $funcName = 'perform' . $transName; //echo "<li>$field->class used $funcName"; return $field->{$funcName}($this); } } // And this one does the reverse. if ($fieldClass = $fieldClasses[$i]) { if ($this->hasMethod('transform' . $fieldClass)) { $funcName = 'transform' . $fieldClass; //echo "<li>$field->class used $funcName"; return $this->{$funcName}($field); } } } user_error("FormTransformation:: Can't perform '{$this->class}' on '{$field->class}'", E_USER_ERROR); }
/** * Transforms all fields in the FieldList to use Bootstrap templates * @return FieldList */ public function bootstrapify() { foreach ($this->owner as $f) { if (isset($this->ignores[$f->getName()])) { continue; } // If we have a Tabset, bootstrapify all Tabs if ($f instanceof TabSet) { $f->Tabs()->bootstrapify(); } // If we have a Tab, bootstrapify all its Fields if ($f instanceof Tab) { $f->Fields()->bootstrapify(); } $template = "Bootstrap{$f->class}_holder"; if (SSViewer::hasTemplate($template)) { $f->setFieldHolderTemplate($template); } else { $f->setFieldHolderTemplate("BootstrapFieldHolder"); } foreach (array_reverse(ClassInfo::ancestry($f)) as $className) { $bootstrapCandidate = "Bootstrap{$className}"; $nativeCandidate = $className; if (SSViewer::hasTemplate($bootstrapCandidate)) { $f->setTemplate($bootstrapCandidate); break; } elseif (SSViewer::hasTemplate($nativeCandidate)) { $f->setTemplate($nativeCandidate); break; } } } return $this->owner; }
/** * @covers ClassInfo::ancestry() */ public function testAncestry() { $ancestry = ClassInfo::ancestry('ClassInfoTest_ChildClass'); $expect = ArrayLib::valuekey(array('Object', 'ViewableData', 'DataObject', 'ClassInfoTest_BaseClass', 'ClassInfoTest_ChildClass')); $this->assertEquals($expect, $ancestry); $ancestry = ClassInfo::ancestry('ClassInfoTest_ChildClass', true); $this->assertEquals(array('ClassInfoTest_BaseClass' => 'ClassInfoTest_BaseClass'), $ancestry, '$tablesOnly option excludes memory-only inheritance classes'); }
public function updateCMSFields(FieldList $fields) { $ancestry = ClassInfo::ancestry($this->owner->ClassName); if (!in_array('RedirectorPage', $ancestry) && !in_array('VirtualPage', $ancestry)) { $blocks = $this->owner->Blocks(); $blocks_grid = $this->gridBuilder('Blocks', $blocks, '', true, 'GridFieldConfig_RelationEditor'); $docked_grid = $this->gridBuilder('DockedBlocks', $this->dockedBlocks(), ''); $fields->addFieldToTab('Root.MyBlocks', $blocks_grid); $fields->addFieldToTab('Root.DockedBlocks', $docked_grid); } }
public function SectionClasses() { $classes = []; foreach (array_reverse(ClassInfo::ancestry($this->class)) as $class) { if ($class == __CLASS__) { break; } $classes[] = "section-type-{$class}"; } return implode(' ', $classes); }
/** * Returns the table name where the sortable field is stored. * * @return string */ public function getSortableTable() { $classes = ClassInfo::ancestry($this->getOtherClass()); $field = $this->getOption('SortableField'); foreach (array_reverse($classes) as $class) { if (singleton($class)->hasOwnTableDatabaseField($field)) { return $class; } } throw new Exception("Could not find the sort field \"{$field}\" on {$this->getOtherClass()}"); }
function getHandler($noun) { $ancestry = array_reverse(ClassInfo::ancestry($noun->class)); foreach ($ancestry as $class) { $class = $class . '_Handler'; if (ClassInfo::exists($class)) { return new $class($noun); } } user_error("Couldn't find a handler for REST Noun " . $noun, E_USER_ERROR); }
public function init() { //setting the uploads directory to make sure images uploaded through the content //editor are saved the right place $curr = LeftAndMain::curr(); if ($curr) { //Debug::dump(get_class($curr)); //Debug::dump(ClassInfo::ancestry($curr)); $currClass = null; foreach (ClassInfo::ancestry($curr) as $class) { foreach (self::$supported_classes as $supported_class) { if ($class == $supported_class) { $currClass = $class; } } } //Debug::dump($currClass); //switch (get_class($curr)) { switch ($currClass) { //Page administration case 'CMSPagesController': case 'CMSPageEditController': $page = $curr->currentPage(); if ($page && $page->hasExtension('AssetsFolderExtension')) { Upload::config()->uploads_folder = $page->getAssetsFolderDirName(); } //Debug::dump($page->Title); break; case 'ModelAdmin': //For ModelAdmin we're falling back to cookies that we believe to have //been set when setting the cms fields, see AssetFolderExtension::updateCMSFields() //...as it seems to be almost impossible to figure out the current object elsewise //see below for tries //pull requests to fix this welcome!!! //Debug::dump($this->owner->getURLParams()); //Debug::dump($this->owner->request->param('ModelClass')); //Debug::dump($this->owner->request->remaining()); //Debug::dump($this->owner->request->getVars()); //Debug::dump($this->owner->request->params()); //Debug::dump($curr->currentPageID()); Upload::config()->uploads_folder = Cookie::get('cms-uploaddirrules-uploads-folder'); break; //Settings //Settings case 'CMSSettingsController': if (Object::has_extension('SiteConfig', 'AssetsFolderExtension')) { $sc = SiteConfig::current_site_config(); Upload::config()->uploads_folder = $sc->getAssetsFolderDirName(); } default: } } }
/** * Most of the code below was copied from ManyManyComplexTableField. * Painful, but necessary, until PHP supports multiple inheritance. */ function __construct($controller, $name, $sourceClass, $fieldList = null, $detailFormFields = null, $sourceFilter = "", $sourceSort = "", $sourceJoin = "") { parent::__construct($controller, $name, $sourceClass, $fieldList, $detailFormFields, $sourceFilter, $sourceSort, $sourceJoin); $manyManyTable = false; $classes = array_reverse(ClassInfo::ancestry($this->controllerClass())); foreach($classes as $class) { if($class != "Object") { $singleton = singleton($class); $manyManyRelations = $singleton->uninherited('many_many', true); if(isset($manyManyRelations) && array_key_exists($this->name, $manyManyRelations)) { $this->manyManyParentClass = $class; $manyManyTable = $class . '_' . $this->name; break; } $belongsManyManyRelations = $singleton->uninherited( 'belongs_many_many', true ); if( isset( $belongsManyManyRelations ) && array_key_exists( $this->name, $belongsManyManyRelations ) ) { $this->manyManyParentClass = $class; // @modification http://open.silverstripe.org/ticket/5194 $manyManyClass = $belongsManyManyRelations[$this->name]; $manyManyRelations = singleton($manyManyClass)->uninherited('many_many', true); foreach($manyManyRelations as $manyManyRelationship => $manyManyChildClass) if ($manyManyChildClass == $class) break; $manyManyTable = $manyManyClass . '_' . $manyManyRelationship; break; } } } if(!$manyManyTable) user_error("I could not find the relation $this->name in " . $this->controllerClass() . " or any of its ancestors.",E_USER_WARNING); $this->manyManyTable = $manyManyTable; $tableClasses = ClassInfo::dataClassesFor($this->sourceClass); $source = array_shift($tableClasses); $sourceField = $this->sourceClass; if($this->manyManyParentClass == $sourceField) $sourceField = 'Child'; $parentID = $this->controller->ID; $this->sourceJoin .= " LEFT JOIN \"$manyManyTable\" ON (\"$source\".\"ID\" = \"{$sourceField}ID\" AND \"$manyManyTable\".\"{$this->manyManyParentClass}ID\" = '$parentID')"; $this->joinField = 'Checked'; if(isset($_REQUEST['ctf'][$this->Name()]['only_related'])) $this->OnlyRelated = $_REQUEST['ctf'][$this->Name()]['only_related']; $this->addPermission('only_related'); if($this->ShowAll() && SortableDataObject::is_sortable_many_many($this->sourceClass())) $this->OnlyRelated = '1'; }
/** * Get a list of templates to call and return a default render with */ public function index() { $classes = ClassInfo::ancestry($this->dataRecord->class); $remove_classes = array("Object", "ViewableData", "DataObject"); $return = array(); array_push($classes, "Category", "Catalogue", "Page"); foreach ($classes as $class) { if (!in_array($class, $remove_classes)) { $return[] = $class; } } return $this->renderWith($return); }
protected function get_index_templates() { $classes = ClassInfo::ancestry($this->dataRecord->class); $classes = array_reverse($classes); $remove_classes = self::config()->classes_to_remove; $return = array(); array_push($classes, "Catalogue", "Page"); foreach ($classes as $class) { if (!in_array($class, $remove_classes)) { $return[] = $class; } } return $return; }
/** * Get a list of templates for rendering * * @param $classname ClassName to find tempaltes for * @return array Array of classnames */ public static function get_templates_for_class($classname) { $classes = ClassInfo::ancestry($classname); $classes = array_reverse($classes); $remove_classes = self::config()->classes_to_remove; $return = array(); array_push($classes, "Catalogue", "Page"); foreach ($classes as $class) { if (!in_array($class, $remove_classes)) { $return[] = $class; } } return $return; }
/** * All subfolders and files sorted by $sort. * * @param $sort * @return DataList */ public function getSortedChildren($sortField = 'Title', $sortDir = 'ASC') { $ancestors = ClassInfo::ancestry($this->owner->class); foreach ($ancestors as $i => $a) { if (isset($baseClass) && $baseClass === -1) { $baseClass = $a; break; } if ($a == "DataObject") { $baseClass = -1; } } return $baseClass::get()->filter(array("ParentID" => $this->owner->ID))->sort($sortField, $sortDir); }
public function Layout() { $page = Director::get_current_page(); $member = Member::currentUser(); $access = Permission::checkMember($member, 'CMS_ACCESS'); $sectionType = get_called_class(); if ($this->Public || $access) { // Added UserDefinedForm to section if (in_array('UserDefinedForm', ClassInfo::ancestry($page->ClassName))) { $result = new UserDefinedForm_Controller($page); $result->init(); $page->Form = $result->Form(); } return $page->renderWith($this->Render()); } }
protected function getExternalType($item) { if ($item->ClassName) { $name = null; $hierarchy = ClassInfo::ancestry($item->ClassName); foreach ($hierarchy as $ancestor => $val) { if (isset($this->contentTransforms[$ancestor])) { $name = $ancestor; } } if ($name) { return $name; } } return 'DataObject'; }
/** * Transforms all fields in the FieldList to use Foundation templates * @return FieldList */ public function bootstrapify() { foreach ($this->owner as $f) { $sng = Injector::inst()->get($f->class, true, ['dummy', '']); if (isset($this->ignores[$f->getName()])) { continue; } // if we have a CompositeField, bootstrapify its children if ($f instanceof CompositeField) { $f->getChildren()->bootstrapify(); continue; } // If we have a Tabset, bootstrapify all Tabs if ($f instanceof TabSet) { $f->Tabs()->bootstrapify(); } // If we have a Tab, bootstrapify all its Fields if ($f instanceof Tab) { $f->Fields()->bootstrapify(); } // If the user has customised the holder template already, don't apply the default one. if ($sng->getFieldHolderTemplate() == $f->getFieldHolderTemplate()) { $template = "Foundation{$f->class}_holder"; if (SSViewer::hasTemplate($template)) { $f->setFieldHolderTemplate($template); } else { $f->setFieldHolderTemplate("FoundationFieldHolder"); } } // If the user has customised the field template already, don't apply the default one. if ($sng->getTemplate() == $f->getTemplate()) { foreach (array_reverse(ClassInfo::ancestry($f)) as $className) { $bootstrapCandidate = "Foundation{$className}"; $nativeCandidate = $className; if (SSViewer::hasTemplate($bootstrapCandidate)) { $f->setTemplate($bootstrapCandidate); break; } elseif (SSViewer::hasTemplate($nativeCandidate)) { $f->setTemplate($nativeCandidate); break; } } } } return $this->owner; }
/** * Get all updatable relations from $this->owner. * * @return array */ protected function updatableRelations() { $updatableRelations = array(); foreach (array_merge($this->owner->has_many(), $this->getExtensionComponents('has_many')) as $hasManyRelation => $hasManyClass) { $hasOneOnVersioning = (array)Object::combined_static($hasManyClass, 'has_one_on_versioning'); foreach ($hasOneOnVersioning as $onUpdateRelation => $process) { $hasOneClass = singleton($hasManyClass)->has_one($onUpdateRelation); if (in_array($hasOneClass, ClassInfo::ancestry($this->owner->ClassName)) && $process) { $updatableRelations[$hasManyRelation] = array( $hasManyClass, $onUpdateRelation ); } } } return $updatableRelations; }
public function WidgetControllers() { $set = new ArrayList(); $items = $this->ItemsToRender(); foreach ($items as $dashlet) { $class = ''; foreach (array_reverse(ClassInfo::ancestry($dashlet->class)) as $class) { if (class_exists($class = "{$class}_Controller")) { break; } } $controller = Injector::inst()->create($class, $dashlet, $this->parent->getController()); $controller->init(); $set->push($controller); } return $set; }
/** * Get the appropriate {@link ContentController} for handling a {@link SiteTree} object, link it to the object and * return it. * * @param SiteTree $sitetree * @param string $action * @return ContentController */ public static function controller_for(SiteTree $sitetree, $action = null) { if ($sitetree->class == 'SiteTree') { $controller = "ContentController"; } else { $ancestry = ClassInfo::ancestry($sitetree->class); while ($class = array_pop($ancestry)) { if (class_exists($class . "_Controller")) { break; } } $controller = $class !== null ? "{$class}_Controller" : "ContentController"; } if ($action && class_exists($controller . '_' . ucfirst($action))) { $controller = $controller . '_' . ucfirst($action); } return class_exists($controller) ? Injector::inst()->create($controller, $sitetree) : $sitetree; }