diff --git a/forms/TreeDropdownField.php b/forms/TreeDropdownField.php index d3d77c83b21..a2ca9be8df4 100644 --- a/forms/TreeDropdownField.php +++ b/forms/TreeDropdownField.php @@ -263,14 +263,28 @@ public function tree(SS_HTTPRequest $request) { $obj->markToExpose($this->objectForKey($value)); } } - $eval = '"
  • getName() . '-{$child->' . $this->keyField . '}\" data-id=\"$child->' - . $this->keyField . '\" class=\"class-$child->class"' - . ' . $child->markingClasses() . "\">ID\">" . $child->' . $this->labelField . ' . ""'; + + $self = $this; + $escapeLabelField = ($obj->escapeTypeForField($this->labelField) != 'xml'); + $titleFn = function(&$child) use(&$self, $escapeLabelField) { + $keyField = $self->keyField; + $labelField = $self->labelField; + return sprintf( + '
  • %s', + Convert::raw2xml($self->getName()), + Convert::raw2xml($child->$keyField), + Convert::raw2xml($child->$keyField), + Convert::raw2xml($child->class), + Convert::raw2xml($child->markingClasses()), + (int)$child->ID, + $escapeLabelField ? Convert::raw2xml($child->$labelField) : $child->$labelField + ); + }; if($isSubTree) { - return substr(trim($obj->getChildrenAsUL('', $eval, null, true, $this->childrenMethod)), 4, -5); + return substr(trim($obj->getChildrenAsUL('', $titleFn, null, true, $this->childrenMethod)), 4, -5); } else { - return $obj->getChildrenAsUL('class="tree"', $eval, null, true, $this->childrenMethod); + return $obj->getChildrenAsUL('class="tree"', $titleFn, null, true, $this->childrenMethod); } } @@ -290,7 +304,7 @@ public function filterMarking($node) { return true; } - + /** * Populate $this->searchIds with the IDs of the pages matching the searched parameter and their parents. * Reverse-constructs the tree starting from the leaves. Initially taken from CMSSiteTreeFilter, but modified