Skip to content
This repository
Browse code

MINOR Moved tree filtering in LeftAndMain from SiteTreeAsUL() into ge…

…tSiteTreeFor() to allow filtering the initial tree (via GET parameters), rather than just through getsubtree()
  • Loading branch information...
commit 0ef5d0b84f1d0101d9c734c500613ee0e289e9a0 1 parent 9b2b39a
Ingo Schommer authored
32  admin/code/LeftAndMain.php
@@ -590,10 +590,22 @@ public function SiteTreeAsUL() {
590 590
 	 * @return String Nested unordered list with links to each page
591 591
 	 */
592 592
 	function getSiteTreeFor($className, $rootID = null, $childrenMethod = null, $numChildrenMethod = null, $filterFunction = null, $minNodeCount = 30) {
  593
+		// Filter criteria
  594
+		$params = $this->request->getVar('q');
  595
+		if(isset($params['FilterClass']) && $filterClass = $params['FilterClass']){
  596
+			if(!is_subclass_of($filterClass, 'CMSSiteTreeFilter')) {
  597
+				throw new Exception(sprintf('Invalid filter class passed: %s', $filterClass));
  598
+			}
  599
+			$filter = new $filterClass($params);
  600
+		} else {
  601
+			$filter = null;
  602
+		}
  603
+
593 604
 		// Default childrenMethod and numChildrenMethod
594  
-		if (!$childrenMethod) $childrenMethod = 'AllChildrenIncludingDeleted';
595  
-		if (!$numChildrenMethod) $numChildrenMethod = 'numChildren';
596  
-		
  605
+		if(!$childrenMethod) $childrenMethod = ($filter && $filter->getChildrenMethod()) ? $filter->getChildrenMethod() : 'AllChildrenIncludingDeleted';
  606
+		if(!$numChildrenMethod) $numChildrenMethod = 'numChildren';
  607
+		if(!$filterFunction) $filterFunction = ($filter) ? array($filter, 'isPageIncluded') : null;
  608
+
597 609
 		// Get the tree root
598 610
 		$record = ($rootID) ? $this->getRecord($rootID) : null;
599 611
 		$obj = $record ? $record : singleton($className);
@@ -657,22 +669,12 @@ function getSiteTreeFor($className, $rootID = null, $childrenMethod = null, $num
657 669
 	 * If ID = 0, then get the whole tree.
658 670
 	 */
659 671
 	public function getsubtree($request) {
660  
-		if($filterClass = $request->requestVar('FilterClass')) {
661  
-			if(!is_subclass_of($filterClass, 'CMSSiteTreeFilter')) {
662  
-				throw new Exception(sprintf('Invalid filter class passed: %s', $filterClass));
663  
-			}
664  
-
665  
-			$filter = new $filterClass($request->requestVars());
666  
-		} else {
667  
-			$filter = null;
668  
-		}
669  
-		
670 672
 		$html = $this->getSiteTreeFor(
671 673
 			$this->stat('tree_class'), 
672 674
 			$request->getVar('ID'), 
673  
-			($filter) ? $filter->getChildrenMethod() : null, 
  675
+			null, 
674 676
 			null,
675  
-			($filter) ? array($filter, 'isPageIncluded') : null, 
  677
+			null, 
676 678
 			$request->getVar('minNodeCount')
677 679
 		);
678 680
 
2  admin/javascript/LeftAndMain.Tree.js
@@ -213,7 +213,7 @@
213 213
 				};
214 214
 
215 215
 				var handledform = $(e.target).is('.cms-edit-form') ? $(e.target)[0] : $(e.target).find('.cms-edit-form')[0];
216  
-				var id = $(handledform.ID).val();
  216
+				var id = handledform ? $(handledform.ID).val() : null;
217 217
 
218 218
 				// check if a form with a valid ID exists
219 219
 				if(id) {

0 notes on commit 0ef5d0b

Please sign in to comment.
Something went wrong with that request. Please try again.