. */ namespace App\Twig; use App\Entity\LogSystem\AbstractLogEntry; use App\Repository\LogEntryRepository; use Doctrine\ORM\EntityManagerInterface; use Twig\Extension\AbstractExtension; use Twig\TwigFunction; class UserExtension extends AbstractExtension { /** @var LogEntryRepository */ private $repo; public function __construct(EntityManagerInterface $em) { $this->repo = $em->getRepository(AbstractLogEntry::class); } public function getFunctions(): array { return [ /* Returns the user which has edited the given entity the last time. */ new TwigFunction('last_editing_user', [$this->repo, 'getLastEditingUser']), /* Returns the user which has created the given entity. */ new TwigFunction('creating_user', [$this->repo, 'getCreatingUser']), ]; } }