sourceObject = $sourceObject; $this->keyField = $keyField; $this->labelField = $labelField; parent::__construct($name, $title); } function setFilterFunction($filterFunc) { $this->filterFunc = $filterFunc; } /** * Set the root node of the tree. Defaults to 0, ie, the whole tree */ function setTreeBaseID($treeBaseID) { $this->treeBaseID = $treeBaseID; } function Field() { Requirements::javascript(THIRDPARTY_DIR . "/prototype.js"); Requirements::javascript(THIRDPARTY_DIR . "/behaviour.js"); Requirements::javascript(THIRDPARTY_DIR . "/prototype_improvements.js"); Requirements::css(SAPPHIRE_DIR . '/css/TreeDropdownField.css'); Requirements::javascript(THIRDPARTY_DIR . "/tree/tree.js"); Requirements::css(THIRDPARTY_DIR . "/tree/tree.css"); Requirements::add_i18n_javascript(SAPPHIRE_DIR . '/javascript/lang'); Requirements::javascript(SAPPHIRE_DIR . "/javascript/TreeSelectorField.js"); if($this->value) { $record = $this->getByKey($this->value); $title = ($record) ? $record->Title : _t('DropdownField.CHOOSE', "(Choose)", PR_MEDIUM, 'Start-value of a dropdown'); } else { $title = _t('DropdownField.CHOOSE', "(Choose)", PR_MEDIUM, 'Start-value of a dropdown'); } $id = $this->id(); $classes = "TreeDropdownField single"; if($this->extraClass()) $classes .= ' ' . $this->extraClass(); return <<$title HTML; } /** * Return the site tree */ function gettree() { if($this->treeBaseID) $obj = DataObject::get_by_id($this->sourceObject, $this->treeBaseID); else $obj = singleton($this->sourceObject); if($this->filterFunc) $obj->setMarkingFilterFunction($this->filterFunc); else if($this->sourceObject == 'Folder') $obj->setMarkingFilter('ClassName', 'Folder'); $obj->markPartialTree(); // If we've already got values selected, make sure that we've got them in our tree if($_REQUEST['forceValues']) { $forceValues = split(" *, *", trim($_REQUEST['forceValues'])); foreach($forceValues as $value) { $obj->markToExpose($this->getByKey($value)); } } $eval = '"