public function ReportEditor::setValue in Forena Reports 7.5
Same name and namespace in other branches
- 8 src/Editor/ReportEditor.php \Drupal\forena\Editor\ReportEditor::setValue()
Set the value of an element within the report
Parameters
String $xpath Xpath to element being saved:
string $value Value to be saved.:
Return value
unknown_type
File
- src/
Editor/ ReportEditor.php, line 224 - ReportEditor.inc Wrapper XML class for working with DOM object. It provides helper Enter description here ... @author metzlerd
Class
Namespace
Drupal\forena\EditorCode
public function setValue($xpath, $value) {
$xml = $this->simplexml;
$i = strrpos($xpath, '/');
$path = substr($xpath, 0, $i);
$key = substr($xpath, $i + 1);
$nodes = $xml
->xpath($path);
if ($nodes) {
// if the last part of the xpath is a key then assume the key
if (strpos($key, '@') === 0) {
$key = trim($key, '@');
if (is_null($value)) {
unset($nodes[0][$key]);
}
else {
$nodes[0][$key] = $value;
}
}
else {
if (is_null($value)) {
unset($nodes[0]->{$key});
}
else {
$nodes[0]->{$key} = $value;
}
}
return TRUE;
}
else {
return FALSE;
}
}