From 2bc6a2be3c3442282f0ff613bce39b129eb94fc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Sun, 23 Feb 2020 20:16:28 +0100 Subject: [PATCH] Show in log which fields were changed in a ElementEditedLogEntry. --- src/Entity/LogSystem/ElementEditedLogEntry.php | 18 ++++++++++++++++++ .../LogSystem/LogEntryExtraFormatter.php | 14 +++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/Entity/LogSystem/ElementEditedLogEntry.php b/src/Entity/LogSystem/ElementEditedLogEntry.php index 0cc400f1..9c84d7a4 100644 --- a/src/Entity/LogSystem/ElementEditedLogEntry.php +++ b/src/Entity/LogSystem/ElementEditedLogEntry.php @@ -62,6 +62,24 @@ class ElementEditedLogEntry extends AbstractLogEntry implements TimeTravelInterf $this->setTargetElement($changed_element); } + /** + * Checks if this log contains infos about which fields has changed. + * @return bool + */ + public function hasChangedFieldsInfo(): bool + { + return $this->hasOldDataInformations(); + } + + /** + * Return the names of all fields that were changed during the change. + * @return string[] + */ + public function getChangedFields(): array + { + return array_keys($this->getOldData()); + } + /** * Sets the old data for this entry. * @param array $old_data diff --git a/src/Services/LogSystem/LogEntryExtraFormatter.php b/src/Services/LogSystem/LogEntryExtraFormatter.php index 941c57e0..8aa56166 100644 --- a/src/Services/LogSystem/LogEntryExtraFormatter.php +++ b/src/Services/LogSystem/LogEntryExtraFormatter.php @@ -144,10 +144,22 @@ class LogEntryExtraFormatter } if ($context instanceof ElementEditedLogEntry) { + $str = ''; if ($context->hasComment()) { - return htmlspecialchars($context->getComment()); + $str .= htmlspecialchars($context->getComment()); } + if ($context->hasChangedFieldsInfo()) { + if (!empty($str)) { + $str .= '; '; + } + $str .= sprintf( + "%s: %s", + $this->translator->trans('log.element_edited.changed_fields'), + htmlspecialchars(implode(', ', $context->getChangedFields())) + ); + } + return $str; } if ($context instanceof InstockChangedLogEntry) {