vendor/bluue/projects-bundle/src/EventSubscriber/CrmBundle/OpportunityViewTabsSubscriber.php line 70

Open in your IDE?
  1. <?php
  2. /**
  3.  * @author Thomas HERISSON (contact@scaledev.fr)
  4.  * @copyright 2021 - ScaleDEV SAS, 12 RUE CHARLES MORET, 10120 ST ANDRE LES VERGERS
  5.  * @license commercial
  6.  */
  7. declare(strict_types=1);
  8. namespace Bluue\ProjectsBundle\EventSubscriber\CrmBundle;
  9. use App\Services\CheckBundleInstall;
  10. use ReflectionClass;
  11. use Symfony\Component\HttpFoundation\RequestStack;
  12. use Symfony\Component\Security\Core\Security;
  13. use Symfony\Contracts\Translation\TranslatorInterface;
  14. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  15. class OpportunityViewTabsSubscriber implements EventSubscriberInterface
  16. {
  17.     /**
  18.      * @var TranslatorInterface
  19.      */
  20.     private TranslatorInterface $tr;
  21.     /**
  22.      * @var RequestStack
  23.      */
  24.     protected RequestStack $requestStack;
  25.     /**
  26.      * @var Security
  27.      */
  28.     private Security $security;
  29.     /**
  30.      * @param RequestStack $requestStack
  31.      * @param TranslatorInterface $tr
  32.      * @param Security $security
  33.      */
  34.     public function __construct(
  35.         RequestStack $requestStack,
  36.         TranslatorInterface $tr,
  37.         Security $security
  38.     ) {
  39.         $this->requestStack $requestStack;
  40.         $this->tr $tr;
  41.         $this->security $security;
  42.     }
  43.     /**
  44.      * @return array
  45.      */
  46.     public static function getSubscribedEvents(): array
  47.     {
  48.         if (CheckBundleInstall::exist('crm-bundle')) {
  49.             $reflectionClass = new ReflectionClass('Bluue\CrmBundle\Event\OpportunityViewTabsEvent');
  50.             return [
  51.                 $reflectionClass->getConstant('NAME') => 'onLoad'
  52.             ];
  53.         }
  54.         return [];
  55.     }
  56.     /**
  57.      * @param object $event
  58.      * @return void
  59.      */
  60.     public function onLoad(object $event)
  61.     {
  62.         $opportunityId $this->requestStack->getMainRequest()->attributes->get('id');
  63.         if (!$opportunityId || !$this->security->isGranted('ROLE__PROJECTS__READ_ONLY')) {
  64.             return;
  65.         }
  66.         $pages $event->getPages();
  67.         $pages[] = [
  68.             'path' => 'projects_bundle__opportunity_tasks',
  69.             'opportunity_id_required' => true,
  70.             'href' => 'task',
  71.             'name' => $this->tr->trans('Trade tasks', [], 'ProjectsBundle')
  72.         ];
  73.         $pages[] = [
  74.             'path' => 'projects_bundle__opportunity_conception_tasks',
  75.             'opportunity_id_required' => true,
  76.             'href' => 'conception_task',
  77.             'name' => $this->tr->trans('Conception tasks', [], 'ProjectsBundle')
  78.         ];
  79.         $event->setPages($pages);
  80.     }
  81. }