diff --git a/application/config/services.yaml b/application/config/services.yaml index b7d3d2c..c5c9ecb 100644 --- a/application/config/services.yaml +++ b/application/config/services.yaml @@ -21,6 +21,11 @@ services: factory: ['@app.menu_builder', 'userTopbar'] tags: - { name: knp_menu.menu, alias: userTopbar } + app.menu.source: + class: Knp\Menu\MenuItem + factory: ['@app.menu_builder', 'sourceNavbar'] + tags: + - { name: knp_menu.menu, alias: sourceNavbar } # makes classes in src/ available to be used as services # this creates a service per class whose id is the fully-qualified class name App\: diff --git a/application/src/Controller/SourceController.php b/application/src/Controller/SourceController.php index 98a6b2e..e0477c9 100644 --- a/application/src/Controller/SourceController.php +++ b/application/src/Controller/SourceController.php @@ -1,4 +1,5 @@ view($source, 200) ->setTemplate((new SourceTemplateFactory($source, $request))->getTemplatePath()) ->setTemplateVar('source'); + return $this->handleView($view); } /** - * * @Route("/source/{id}/edit.{_format}", defaults={"_format"="html"}) */ public function edit(Request $request, int $id): Response @@ -44,9 +44,10 @@ class SourceController extends FOSRestController $source = $form->getData(); $this->saveSource($source); } - return $this->render((new SourceTemplateFormFactory($source, $request))->getTemplatePath(), array( + + return $this->render((new SourceTemplateFormFactory($source, $request))->getTemplatePath(), [ 'form' => $form->createView(), - )); + ]); } private function loadSource(Request $request, int $id): SourceInterface @@ -54,9 +55,10 @@ class SourceController extends FOSRestController $source = $this->getDoctrine() ->getRepository(AbstractSource::class) ->find($id); - if (! $source) { - throw $this->createNotFoundException('No source found for id ' . $id); + if (!$source) { + throw $this->createNotFoundException('No source found for id '.$id); } + return $source; } diff --git a/application/src/Creator/Factory/Form/Source/SourceFormFactory.php b/application/src/Creator/Factory/Form/Source/SourceFormFactory.php index b9c88ce..0be64e9 100644 --- a/application/src/Creator/Factory/Form/Source/SourceFormFactory.php +++ b/application/src/Creator/Factory/Form/Source/SourceFormFactory.php @@ -1,34 +1,35 @@ source = $source; } - - public function getNamespace():string{ + + public function getNamespace(): string + { return self::FORM_NAMESPACE.$this->getName(); } - + protected function getName(): string { $reflectionClass = new \ReflectionClass($this->source); + return $reflectionClass->getShortName().'Type'; } } - diff --git a/application/src/Creator/Factory/Template/Source/SourceTemplateFactory.php b/application/src/Creator/Factory/Template/Source/SourceTemplateFactory.php index f05730a..80c2932 100644 --- a/application/src/Creator/Factory/Template/Source/SourceTemplateFactory.php +++ b/application/src/Creator/Factory/Template/Source/SourceTemplateFactory.php @@ -13,7 +13,7 @@ class SourceTemplateFactory const SOURCE_TEMPLATE_ROOT = 'source'; const VIEW_FOLDER = 'view'; - + /** * @var SourceInterface */ diff --git a/application/src/Creator/Factory/Template/Source/SourceTemplateFormFactory.php b/application/src/Creator/Factory/Template/Source/SourceTemplateFormFactory.php index bb2cd68..45bdf90 100644 --- a/application/src/Creator/Factory/Template/Source/SourceTemplateFormFactory.php +++ b/application/src/Creator/Factory/Template/Source/SourceTemplateFormFactory.php @@ -1,18 +1,16 @@ generateName().'.'.$this->request->getRequestFormat().'.twig'; } } - diff --git a/application/src/Entity/NameSource.php b/application/src/Entity/NameSource.php index 69e1928..fdd538c 100644 --- a/application/src/Entity/NameSource.php +++ b/application/src/Entity/NameSource.php @@ -18,6 +18,7 @@ class NameSource extends AbstractSource implements NameSourceInterface /** * @ORM\Column(type="string",length=255) * @Assert\NotBlank() + * * @var string */ protected $name; diff --git a/application/src/Event/Menu/Topbar/SourceMenuEvent.php b/application/src/Event/Menu/Topbar/SourceMenuEvent.php new file mode 100644 index 0000000..cc8d49c --- /dev/null +++ b/application/src/Event/Menu/Topbar/SourceMenuEvent.php @@ -0,0 +1,59 @@ +factory = $factory; + $this->item = $item; + $this->request = $request; + } + + /** + * @return FactoryInterface + */ + public function getFactory(): FactoryInterface + { + return $this->factory; + } + + /** + * @return ItemInterface + */ + public function getItem(): ItemInterface + { + return $this->item; + } + + /** + * @return RequestStack + */ + public function getRequest(): RequestStack + { + return $this->request; + } +} diff --git a/application/src/Menu/Menu.php b/application/src/Menu/Menu.php index e82281b..1519e9f 100644 --- a/application/src/Menu/Menu.php +++ b/application/src/Menu/Menu.php @@ -1,7 +1,5 @@ factory = $factory; } + public function SourceNavbar(RequestStack $request): ItemInterface + { + $menu = $this->factory->createItem('root', [ + 'childrenAttributes' => [ + 'class' => 'navbar-nav mr-auto', + ], + ]); + + $this->dispatcher->dispatch(SourceMenuEvent::EVENT, new SourceMenuEvent($this->factory, $menu, $request)); + + return $menu; + } + public function userTopbar(RequestStack $request): ItemInterface { $menu = $this->factory->createItem('root', [ @@ -36,10 +48,7 @@ class Menu ], ]); - $this->dispatcher->dispatch( - UserMenuEvent::EVENT, - new UserMenuEvent($this->factory, $menu, $request) - ); + $this->dispatcher->dispatch(UserMenuEvent::EVENT, new UserMenuEvent($this->factory, $menu, $request)); return $menu; } diff --git a/application/src/Subscriber/SourceMenuSubscriber.php b/application/src/Subscriber/SourceMenuSubscriber.php new file mode 100644 index 0000000..2c4a00e --- /dev/null +++ b/application/src/Subscriber/SourceMenuSubscriber.php @@ -0,0 +1,53 @@ +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', + ], + ]); + $menu->addChild($this->translator->trans('show'), [ + 'route' => 'app_source_show', + 'routeParameters' => ['id' => $event->getRequest()->getCurrentRequest()->attributes->get('id')], + 'attributes' => [ + 'icon' => 'fas fa-eye', + ], + ]); + } + + public static function getSubscribedEvents(): array + { + return [ + SourceMenuEvent::EVENT => 'onSourceMenuConfigure', + ]; + } +} diff --git a/application/src/Subscriber/UserMenuSubscriber.php b/application/src/Subscriber/UserMenuSubscriber.php index 4286c98..919c729 100644 --- a/application/src/Subscriber/UserMenuSubscriber.php +++ b/application/src/Subscriber/UserMenuSubscriber.php @@ -1,4 +1,5 @@ tokenStorage = $tokenStorage; @@ -31,18 +29,18 @@ class UserMenuSubscriber implements EventSubscriberInterface public function onUserMenuConfigure(UserMenuEvent $event): void { $menu = $event->getItem(); - $menu->addChild('start', [ + $menu->addChild($this->translator->trans('start'), [ 'route' => 'homepage', 'attributes' => [ - 'icon' => 'fab fa-font-awesome-flag' - ] + 'icon' => 'fab fa-font-awesome-flag', + ], ]); - - $menu->addChild('imprint', [ + + $menu->addChild($this->translator->trans('imprint'), [ 'route' => 'imprint', 'attributes' => [ - 'icon' => 'fas fa-address-card' - ] + 'icon' => 'fas fa-address-card', + ], ]); $this->generateUserDropdown($menu); } @@ -53,45 +51,45 @@ class UserMenuSubscriber implements EventSubscriberInterface ->getUsername() ?? 'user', [ 'attributes' => [ 'dropdown' => true, - 'icon' => 'fas fa-user' - ] + 'icon' => 'fas fa-user', + ], ]); if ($this->tokenStorage->getToken()->getRoles()) { - $dropdown->addChild('logout', [ + $dropdown->addChild($this->translator->trans('logout'), [ 'route' => 'logout', 'attributes' => [ 'icon' => 'fas fa-sign-out-alt', - 'divider_append' => true - ] + 'divider_append' => true, + ], ]); - $dropdown->addChild('edit profile', [ + $dropdown->addChild($this->translator->trans('edit profile'), [ 'route' => 'fos_user_profile_edit', 'attributes' => [ 'icon' => 'fas fa-user-edit', - 'divider_append' => true - ] + 'divider_append' => true, + ], ]); } else { - $dropdown->addChild('login', [ + $dropdown->addChild($this->translator->trans('login'), [ 'route' => 'fos_user_security_login', 'attributes' => [ 'divider_append' => true, - 'icon' => 'fas fa-sign-in-alt' - ] + 'icon' => 'fas fa-sign-in-alt', + ], ]); } $dropdown->addChild('register', [ 'route' => 'fos_user_registration_register', 'attributes' => [ - 'icon' => 'fas fa-file-signature' - ] + 'icon' => 'fas fa-file-signature', + ], ]); } public static function getSubscribedEvents(): array { return [ - UserMenuEvent::EVENT => 'onUserMenuConfigure' + UserMenuEvent::EVENT => 'onUserMenuConfigure', ]; } } diff --git a/application/templates/frames/structure/navbar/source_sub.html.twig b/application/templates/frames/structure/navbar/source_sub.html.twig new file mode 100644 index 0000000..e4f004d --- /dev/null +++ b/application/templates/frames/structure/navbar/source_sub.html.twig @@ -0,0 +1,11 @@ + diff --git a/application/templates/source/form/source.html.twig b/application/templates/source/form/source.html.twig index 58eb82d..741a135 100644 --- a/application/templates/source/form/source.html.twig +++ b/application/templates/source/form/source.html.twig @@ -1,6 +1,6 @@ -{% extends "frames/default.html.twig" %} +{% extends "source/source.html.twig" %} {% block title %} {% trans %} - Source + Source edit {% endtrans %} {% endblock %} \ No newline at end of file diff --git a/application/templates/source/source.html.twig b/application/templates/source/source.html.twig new file mode 100644 index 0000000..208c6df --- /dev/null +++ b/application/templates/source/source.html.twig @@ -0,0 +1,9 @@ +{% extends "frames/default.html.twig" %} +{% block title %} + {% trans %} + Source + {% endtrans %} +{% endblock %} +{% block sub_navigation %} + {% include 'frames/structure/navbar/source_sub.html.twig'%} +{% endblock %} \ No newline at end of file diff --git a/application/templates/source/view/source.html.twig b/application/templates/source/view/source.html.twig index 8586f6d..be1ca6f 100644 --- a/application/templates/source/view/source.html.twig +++ b/application/templates/source/view/source.html.twig @@ -1,4 +1,4 @@ -{% extends "frames/default.html.twig" %} +{% extends "source/source.html.twig" %} {% block title %} {% trans %} Source