Permalink
Browse files

ENHANCEMENT Support for anonymous functions instead of eval() in Hier…

…archy->getSiteTreeAsUL()
  • Loading branch information...
1 parent 35d4cd3 commit 761bae34187e79fd908f121a16270aceb0f89202 @chillu chillu committed Apr 17, 2012
Showing with 3 additions and 2 deletions.
  1. +3 −2 model/Hierarchy.php
View
5 model/Hierarchy.php
@@ -34,7 +34,7 @@ static function add_to_class($class, $extensionClass, $args = null) {
* Returns the children of this DataObject as an XHTML UL. This will be called recursively on each child,
* so if they have children they will be displayed as a UL inside a LI.
* @param string $attributes Attributes to add to the UL.
- * @param string $titleEval PHP code to evaluate to start each child - this should include '<li>'
+ * @param string|callable $titleEval PHP code to evaluate to start each child - this should include '<li>'
* @param string $extraArg Extra arguments that will be passed on to children, for if they overload this function.
* @param boolean $limitToMarked Display only marked children.
* @param string $childrenMethod The name of the method used to get children from each object
@@ -64,7 +64,8 @@ public function getChildrenAsUL($attributes = "", $titleEval = '"<li>" . $child-
foreach($children as $child) {
if(!$limitToMarked || $child->isMarked()) {
$foundAChild = true;
- $output .= eval("return $titleEval;") . "\n" .
+ $output .= (is_callable($titleEval)) ? $titleEval($child) : eval("return $titleEval;");
+ $output .= "\n" .
$child->getChildrenAsUL("", $titleEval, $extraArg, $limitToMarked, $childrenMethod, $numChildrenMethod, false, $minNodeCount) . "</li>\n";
}
}

0 comments on commit 761bae3

Please sign in to comment.