From 37ce7c399c1c6e04f6fa59a97c22df33f0ae668c Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Fri, 14 Sep 2018 16:05:47 +0200 Subject: [PATCH] Implemented source templates --- .../src/Controller/ActivationInterface.php | 15 ------ .../src/Controller/CreationInterface.php | 15 ------ .../src/Controller/ModificationInterface.php | 13 ----- .../src/Controller/SourceController.php | 35 ++++++------- .../Controller/SourceControllerInterface.php | 13 ----- application/src/Entity/UserSource.php | 1 + application/src/Form/NameSourceType.php | 2 +- application/src/Form/UserSourceType.php | 5 +- application/src/Source/TemplateGenerator.php | 50 +++++++++++++++++++ application/templates/base.html.twig | 2 +- application/templates/source/name.html.twig | 4 ++ 11 files changed, 77 insertions(+), 78 deletions(-) delete mode 100644 application/src/Controller/ActivationInterface.php delete mode 100644 application/src/Controller/CreationInterface.php delete mode 100644 application/src/Controller/ModificationInterface.php delete mode 100644 application/src/Controller/SourceControllerInterface.php create mode 100644 application/src/Source/TemplateGenerator.php create mode 100644 application/templates/source/name.html.twig diff --git a/application/src/Controller/ActivationInterface.php b/application/src/Controller/ActivationInterface.php deleted file mode 100644 index 5d9f984..0000000 --- a/application/src/Controller/ActivationInterface.php +++ /dev/null @@ -1,15 +0,0 @@ -getDoctrine() + ->getRepository(AbstractSource::class) + ->find($id); + if (!$source) { + throw $this->createNotFoundException('No source found for id '.$id); + } + $templateGenerator = new TemplateGenerator($source, $request); - public function activate(): Response - { - } - - public function create(): Response - { - } - - public function delete(): Response - { - } - - public function deactivate(): Response - { + return $this->render($templateGenerator->getTemplatePath(), ['source' => $source]); } } diff --git a/application/src/Controller/SourceControllerInterface.php b/application/src/Controller/SourceControllerInterface.php deleted file mode 100644 index afc396a..0000000 --- a/application/src/Controller/SourceControllerInterface.php +++ /dev/null @@ -1,13 +0,0 @@ -add('name', TextType::class); } - + public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults([ diff --git a/application/src/Form/UserSourceType.php b/application/src/Form/UserSourceType.php index 21f0127..578205f 100644 --- a/application/src/Form/UserSourceType.php +++ b/application/src/Form/UserSourceType.php @@ -1,4 +1,5 @@ add('namesource', NameSourceType::class); @@ -17,8 +17,7 @@ class UserSourceType extends AbstractType public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults([ - 'data_class' => User::class + 'data_class' => User::class, ]); } } - diff --git a/application/src/Source/TemplateGenerator.php b/application/src/Source/TemplateGenerator.php new file mode 100644 index 0000000..93af0b6 --- /dev/null +++ b/application/src/Source/TemplateGenerator.php @@ -0,0 +1,50 @@ +source = $source; + $this->request = $request; + $this->format = $this->request->getRequestFormat(); + } + + public function getTemplatePath(): string + { + return self::SOURCE_TEMPLATE_ROOT.'/'.$this->generateName().'.'.$this->format.'.twig'; + } + + private function generateName(): string + { + $reflection = new \ReflectionClass($this->source); + $shortName = $reflection->getShortName(); + $lowerName = strtolower($shortName); + + return str_replace('source', '', $lowerName); + } +} diff --git a/application/templates/base.html.twig b/application/templates/base.html.twig index cf66b92..ca50a29 100644 --- a/application/templates/base.html.twig +++ b/application/templates/base.html.twig @@ -1,7 +1,7 @@ - {% block title %}Online Shop{% endblock %} + {% block title %}infinito{% endblock %} diff --git a/application/templates/source/name.html.twig b/application/templates/source/name.html.twig new file mode 100644 index 0000000..b80d06f --- /dev/null +++ b/application/templates/source/name.html.twig @@ -0,0 +1,4 @@ +{% extends "frames/default.html.twig" %} +{% block content %} +{{ source.name }} +{% endblock %}