diff --git a/resources/views/revision_timeline.blade.php b/resources/views/revision_timeline.blade.php index fff2cfd..a68faad 100644 --- a/resources/views/revision_timeline.blade.php +++ b/resources/views/revision_timeline.blade.php @@ -1,43 +1,59 @@
@foreach($revisions as $revisionDate => $dateRevisions) -
- {{ Carbon\Carbon::parse($revisionDate)->isoFormat(config('backpack.base.default_date_format')) }} -
+
+ {{ Carbon\Carbon::parse($revisionDate)->isoFormat(config('backpack.base.default_date_format')) }} +
- @foreach($dateRevisions as $history) -
+ @foreach($dateRevisions as $history) +
- @if($history->key == 'created_at' && !$history->old_value) -
- {{ date('h:ia', strtotime($history->created_at)) }} - - {{ $history->userResponsible()?$history->userResponsible()->name:trans('revise-operation::revise.guest_user') }} {{ trans('revise-operation::revise.created_this') }} {{ $crud->entity_name }} + @if($history->key == 'created_at' && !$history->old_value) +
+ {{ date('h:ia', strtotime($history->created_at)) }} - + {{ $history->userResponsible()?$history->userResponsible()->name:trans('revise-operation::revise.guest_user') }} {{ trans('revise-operation::revise.created_this') }} {{ $crud->entity_name }} +
+ @else +
+ {{ date('h:ia', strtotime($history->created_at)) }} - + {{ $history->userResponsible()?$history->userResponsible()->name:trans('revise-operation::revise.guest_user') }} {{ trans('revise-operation::revise.changed_the') }} {{ $history->fieldName() }} +
+
+ {!! csrf_field() !!} + +
+
+
+
+
+
{{ mb_ucfirst(trans('revise-operation::revise.from')) }}:
+
{{ mb_ucfirst(trans('revise-operation::revise.to')) }}:
+
+
+
+ @if($entry->translationEnabled() && $entry->isTranslatableAttribute($history->key) && $crud->getOperationSetting('parseTranslatedRevisions')) + @foreach(json_decode($history->oldValue(), true) ?? [] as $locale => $value) +

{{ strtoupper($locale) }}: {{$value}}

+ @endforeach + @else + {{ $history->oldValue() }} + @endif +
+
+ @if($entry->translationEnabled() && $entry->isTranslatableAttribute($history->key) && $crud->getOperationSetting('parseTranslatedRevisions')) + @foreach(json_decode($history->newValue(), true) ?? [] as $locale => $value) +

{{ strtoupper($locale) }}: {{$value}}

+ @endforeach + @else + {{ $history->newValue() }} + @endif +
+
+
+ @endif
- @else -
- {{ date('h:ia', strtotime($history->created_at)) }} - - {{ $history->userResponsible()?$history->userResponsible()->name:trans('revise-operation::revise.guest_user') }} {{ trans('revise-operation::revise.changed_the') }} {{ $history->fieldName() }} -
-
- {!! csrf_field() !!} - -
-
-
-
-
-
{{ mb_ucfirst(trans('revise-operation::revise.from')) }}:
-
{{ mb_ucfirst(trans('revise-operation::revise.to')) }}:
-
-
-
{{ $history->oldValue() }}
-
{{ $history->newValue() }}
-
-
- @endif -
- @endforeach + @endforeach @endforeach
diff --git a/src/ReviseOperation.php b/src/ReviseOperation.php index 1c3ddac..72cdf72 100644 --- a/src/ReviseOperation.php +++ b/src/ReviseOperation.php @@ -117,10 +117,19 @@ public function restoreRevision($id) $entry = $this->crud->getEntryWithoutFakes($id); $revision = Revision::findOrFail($revisionId); - // Update the revisioned field with the old value - $entry->update([$revision->key => $revision->old_value]); + if (method_exists($entry, 'isTranslatableAttribute') && $entry->isTranslatableAttribute($revision->key)) { + $oldValueAsArray = json_decode($revision->old_value, true); + $entry->forgetTranslations($revision->key); + foreach ($oldValueAsArray as $locale => $value) { + $entry->setTranslation($revision->key, $locale, $value); + } + $entry->save(); + } else { + // Update the revisioned field with the old value + $entry->update([$revision->key => $revision->old_value]); + } - $this->data['entry'] = $this->crud->getEntry($id); + $this->data['entry'] = $entry; $this->data['crud'] = $this->crud; $this->data['revisions'] = $this->crud->getRevisionsForEntry($id); // Reload revisions as they have changed