1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
namespace App\Utils;
use App\Entity\SolidoumeItem;
use Gedmo\Loggable\Entity\LogEntry;
use Gedmo\Loggable\Entity\Repository\LogEntryRepository;
use Sonata\AdminBundle\Show\ShowMapper;
/**
* Trait use for Sonata Admin to print historic of changed to show view.
*/
trait LogEntryTrait
{
protected function addLogEntries(ShowMapper &$showMapper, $class = 'col-12'): void
{
$em = $this->getConfigurationPool()->getContainer()->get('doctrine');
$logEntryRepository = $em->getRepository(LogEntry::class);
$object = $showMapper->getAdmin()->getSubject();
if (null !== $showMapper && null !== $object && null !== $logEntryRepository && count($this->getLogEntries($object)) > 0) {
$showMapper
->with('Versions', ['class' => $class])
->add('logentries', null, [
'label' => false,
'template' => '@kohinos/history/logentries.html.twig',
])
->end()
;
}
}
public function getLogEntries($object)
{
$em = $this->getConfigurationPool()->getContainer()->get('doctrine');
$logEntryRepository = $em->getRepository(LogEntry::class);
return $logEntryRepository->getLogEntries($object);
}
public function getLogEntryMappingClassName(string $className)
{
switch ($className) {
case SolidoumeItem::class:
return "Soli'Item";
default:
return $className;
}
}
}