Visualize generic object/JSON data of element history data as pretty tree structure on log detail page

This commit is contained in:
Jan Böhmer 2023-05-15 23:55:36 +02:00
parent 9be3eba694
commit 272684e7eb
4 changed files with 57 additions and 1 deletions

View file

@ -88,13 +88,23 @@ class LogDataFormatter
}
return htmlspecialchars(json_encode($data, JSON_PRETTY_PRINT));
return $this->formatJSON($data);
}
throw new \RuntimeException('Type of $data not supported (' . gettype($data) . ')');
}
private function formatJSON(array $data): string
{
$json = htmlspecialchars(json_encode($data, JSON_PRETTY_PRINT), ENT_QUOTES | ENT_SUBSTITUTE);
return sprintf(
'<div data-controller="elements--json-formatter" data-json="%s"></div>',
$json
);
}
private function formatForeignKey(array $data, AbstractLogEntry $logEntry, string $fieldName): string
{
//Extract the id from the @id key