diff --git a/forms/TreeDropdownField.php b/forms/TreeDropdownField.php
index d3d77c83b..a2ca9be8d 100644
--- a/forms/TreeDropdownField.php
+++ b/forms/TreeDropdownField.php
@@ -263,14 +263,28 @@ class TreeDropdownField extends FormField {
$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 @@ class TreeDropdownField extends FormField {
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