Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

API-CHANGE: SSF-30 adding a method to control a parameter passed to H…

…ierarchy->getChildrenAsUL() from TreeDropdownField. The parameter is useful for controlling whether the returned UL contains child nodes, or just folders.
  • Loading branch information...
commit 5967a1c13594da234d002f89f39ca4e2dee54c8c 1 parent 13c7c01
@candidasa candidasa authored
Showing with 14 additions and 3 deletions.
  1. +14 −3 forms/TreeDropdownField.php
View
17 forms/TreeDropdownField.php
@@ -54,6 +54,7 @@ class TreeDropdownField extends FormField {
* @ignore
*/
protected $sourceObject, $keyField, $labelField, $filterCallback, $searchCallback, $baseID = 0;
+ protected $childrenMethod = 'AllChildrenIncludingDeleted'; //default child method in Hierarcy->getChildrenAsUL
/**
* Used by field search to leave only the relevant entries
@@ -144,6 +145,16 @@ public function setShowSearch($bool) {
}
/**
+ * @param $method The parameter to ChildrenMethod to use when calling Hierarchy->getChildrenAsUL in {@link Hierarchy}.
+ * The method specified determined the structure of the returned list. Use "ChildFolders" in place of the default
+ * to get a drop-down listing with only folders, i.e. not including the child elements in the currently selected folder.
+ * See {@link Hierarchy} for a complete list of possible methods.
+ */
+ public function setChildrenMethod($method) {
+ $this->childrenMethod = $method;
+ }
+
+ /**
* @return string
*/
public function Field($properties = array()) {
@@ -244,11 +255,11 @@ public function tree(SS_HTTPRequest $request) {
}
$eval = '"<li id=\"selector-' . $this->getName() . '-{$child->' . $this->keyField . '}\" data-id=\"$child->' . $this->keyField . '\" class=\"class-$child->class"' .
' . $child->markingClasses() . "\"><a rel=\"$child->ID\">" . $child->' . $this->labelField . ' . "</a>"';
-
+
if($isSubTree) {
- return substr(trim($obj->getChildrenAsUL('', $eval, null, true)), 4, -5);
+ return substr(trim($obj->getChildrenAsUL('', $eval, null, true, $this->childrenMethod)), 4, -5);
} else {
- return $obj->getChildrenAsUL('class="tree"', $eval, null, true);
+ return $obj->getChildrenAsUL('class="tree"', $eval, null, true, $this->childrenMethod);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.