<?php
declare(strict_types=1);
namespace Bluue\ProjectsBundle\EventSubscriber;
use Bluue\ProjectsBundle\Event\ProjectViewTabsEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
class ProjectViewTabsSubscriber implements EventSubscriberInterface
{
/**
* @var TranslatorInterface
*/
private TranslatorInterface $tr;
/**
* @param TranslatorInterface $tr
*/
public function __construct(TranslatorInterface $tr)
{
$this->tr = $tr;
}
/**
* @return string[]
*/
public static function getSubscribedEvents(): array
{
return [
ProjectViewTabsEvent::NAME => 'viewTabs'
];
}
/**
* @param ProjectViewTabsEvent $event
* @return void
*/
public function viewTabs(ProjectViewTabsEvent $event): void
{
$tabs = $event->getTabs();
$newTabs = [
[
'name' => $this->tr->trans('Time spent', [], 'ProjectsBundle'),
'icon' => 'fas fa-calendar-alt',
'key' => 'time_spent',
'render' => 'Bluue\\ProjectsBundle\\Controller\\TaskController::timeSpent',
'params' => [
'id' => $event->getId(),
'entity' => 'project'
],
]
];
$event->setTabs(array_merge($tabs, $newTabs));
}
}