translator = $translator; } /** * @param ItemInterface $menu * @param Event $event * @param string $route */ protected function generateShowDropdown(ItemInterface $menu, Event $event, string $route): void { $dropdown = $menu->addChild($this->trans('format'), [ 'attributes' => [ 'icon' => 'fas fa-file', 'dropdown' => 'true', ], ]); foreach (RESTResponseType::getValues() as $format) { $dropdown->addChild($format, [ 'route' => $route, 'routeParameters' => $this->getRequestAttributsSubstitutedFormat($event, $format), 'attributes' => [ 'icon' => 'fas fa-sign-out-alt', 'divider_append' => true, ], ]); } $dropdown->addChild($this->trans('standard'), [ 'route' => $route, 'routeParameters' => $this->getRequestAttributs($event), 'attributes' => [ 'icon' => 'fas fa-sign-out-alt', ], ]); } /** * @param string $id * @param array $parameter * * @return string */ protected function trans(string $id, array $parameter = []): string { return $this->translator->trans($id, $parameter); } /** * @param Event $event * * @return Request */ private function getCurrentRequest(Event $event): Request { return $event->getRequest()->getCurrentRequest(); } /** * @param Event $event * * @return ParameterBag */ protected function getRequestAttributs(Event $event): array { return $this->getCurrentRequest($event)->attributes->get('_route_params') ?? []; } /** * @param Event $event * @param string $format * * @return number|string */ private function getRequestAttributsSubstitutedFormat(Event $event, string $format): array { $attributs = $this->getRequestAttributs($event); $attributs[AbstractController::FORMAT_PARAMETER_KEY] = $format; return $attributs; } }