tokenStorage = $tokenStorage; $this->translator = $translator; } public function onSourceMenuConfigure(SourceMenuEvent $event): void { $menu = $event->getItem(); $menu->addChild($this->translator->trans('edit'), [ 'route' => 'app_source_edit', 'routeParameters' => [ 'id' => $event->getRequest()->getCurrentRequest()->attributes->get('id'), ], 'attributes' => [ 'icon' => 'fas fa-edit', ], ]); $this->generateSourceFormatDropdown($menu, $event); $menu->addChild($this->translator->trans('node'), [ 'route' => 'app_source_node', 'routeParameters' => [ 'id' => $event->getRequest()->getCurrentRequest()->attributes->get('id'), ], 'attributes' => [ 'icon' => 'fas fa-globe', ], ]); } private function generateSourceFormatDropdown(ItemInterface $menu, SourceMenuEvent $event): void { $dropdown = $menu->addChild($this->translator->trans('show'), [ 'attributes' => [ 'icon' => 'fas fa-eye', 'dropdown' => 'true', ], ]); foreach ([ 'html', 'json', 'xml', ] as $format) { $dropdown->addChild($format, [ 'route' => 'app_source_show', 'routeParameters' => [ 'id' => $event->getRequest()->getCurrentRequest()->attributes->get('id'), '_format' => $format, ], 'attributes' => [ 'icon' => 'fas fa-sign-out-alt', 'divider_append' => true, ], ]); } $dropdown->addChild($this->translator->trans('standard'), [ 'route' => 'app_source_show', 'routeParameters' => [ 'id' => $event->getRequest()->getCurrentRequest()->attributes->get('id'), ], 'attributes' => [ 'icon' => 'fas fa-sign-out-alt', ], ]); } public static function getSubscribedEvents(): array { return [ SourceMenuEvent::EVENT => 'onSourceMenuConfigure', ]; } }