diff --git a/src/Controller/PartController.php b/src/Controller/PartController.php index df802612..cc43be73 100644 --- a/src/Controller/PartController.php +++ b/src/Controller/PartController.php @@ -37,6 +37,7 @@ use App\Entity\Category; use App\Entity\Part; use App\Form\PartType; use App\Services\AttachmentFilenameService; +use App\Services\EntityURLGenerator; use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; @@ -70,7 +71,7 @@ class PartController extends AbstractController * @param Part $part * @return \Symfony\Component\HttpFoundation\Response */ - public function edit(Part $part, Request $request, EntityManagerInterface $em, TranslatorInterface $translator) + public function edit(Part $part, Request $request, EntityManagerInterface $em) { $form = $this->createForm(PartType::class, $part); @@ -85,7 +86,7 @@ class PartController extends AbstractController return $this->render('edit_part_info.html.twig', [ "part" => $part, - "form" => $form->createView() + "form" => $form->createView(), ]); } diff --git a/src/Form/PartType.php b/src/Form/PartType.php index 031eb9ef..e104814b 100644 --- a/src/Form/PartType.php +++ b/src/Form/PartType.php @@ -33,7 +33,6 @@ namespace App\Form; use App\Entity\Part; -use phpDocumentor\Reflection\Types\Integer; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\TextareaType; use Symfony\Component\Form\Extension\Core\Type\UrlType; @@ -49,14 +48,18 @@ class PartType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options) { $builder - ->add('name', TextType::class, ['empty_data'=>'', 'label'=> 'name.label']) - ->add('description', TextType::class, ['required'=>false, 'empty_data'=>'', 'label'=> 'description.label']) - ->add('instock', IntegerType::class, ['attr' => ['min'=>0], 'label'=> 'instock.label']) - ->add('mininstock', IntegerType::class, ['attr' => ['min'=>0], 'label'=> 'mininstock.label']) + ->add('name', TextType::class, ['empty_data'=>'', 'label'=> 'name.label', + 'attr' => ['placeholder' => 'part.name.placeholder']]) + ->add('description', TextType::class, ['required'=>false, 'empty_data'=>'', + 'label'=> 'description.label', 'help' => 'bbcode.hint', 'attr' => ['placeholder' => 'part.description.placeholder']]) + ->add('instock', IntegerType::class, + ['attr' => ['min'=>0, 'placeholder' => 'part.instock.placeholder'], 'label'=> 'instock.label']) + ->add('mininstock', IntegerType::class, + ['attr' => ['min'=>0, 'placeholder' => 'part.mininstock.placeholder'], 'label'=> 'mininstock.label']) ->add('manufacturer_product_url', UrlType::class, ['required'=>false, 'empty_data' => '', 'label'=> 'manufacturer_url.label']) ->add('comment', TextareaType::class, ['required'=>false, - 'label'=> 'comment.label', 'attr' => ['rows'=> 4]]) + 'label'=> 'comment.label', 'attr' => ['rows'=> 4], 'help' => 'bbcode.hint']) //Buttons ->add('save', SubmitType::class, ['label' => 'part.edit.save']) diff --git a/src/Services/EntityURLGenerator.php b/src/Services/EntityURLGenerator.php index a7104c4d..3c653c49 100644 --- a/src/Services/EntityURLGenerator.php +++ b/src/Services/EntityURLGenerator.php @@ -69,6 +69,27 @@ class EntityURLGenerator throw new EntityNotSupported('The given entity is not supported yet!'); } + public function editURL($entity) : string + { + if($entity instanceof Part) + { + return $this->urlGenerator->generate('part_edit', ['id' => $entity->getID()]); + } + + //Otherwise throw an error + throw new EntityNotSupported('The given entity is not supported yet!'); + } + + public function createURL($entity) : string + { + if($entity instanceof Part) + { + return $this->urlGenerator->generate('part_new'); + } + + throw new EntityNotSupported('The given entity is not supported yet!'); + } + /** * Generates an HTML link to the info page about the given entity. * @param $entity mixed The entity for which the info link should be generated. diff --git a/src/Twig/AppExtension.php b/src/Twig/AppExtension.php new file mode 100644 index 00000000..e3433d9f --- /dev/null +++ b/src/Twig/AppExtension.php @@ -0,0 +1,70 @@ +entityURLGenerator = $entityURLGenerator; + } + + public function getFilters() + { + return [ + new TwigFilter('entityURL', [$this, 'generateEntityURL']) + ]; + } + + public function generateEntityURL(DBElement $entity, string $method = 'info') : string + { + switch($method) { + case 'info': + return $this->entityURLGenerator->infoURL($entity); + case 'edit': + return $this->entityURLGenerator->editURL($entity); + case 'create': + return $this->entityURLGenerator->createURL($entity); + } + + throw new \InvalidArgumentException('method is not supported!'); + } + +} \ No newline at end of file diff --git a/templates/edit_part_info.html.twig b/templates/edit_part_info.html.twig index f4a858bb..7cebbf80 100644 --- a/templates/edit_part_info.html.twig +++ b/templates/edit_part_info.html.twig @@ -7,6 +7,7 @@ {% block card_title %} {% trans with {'%name%': part.name} %}part.edit.card_title{% endtrans %} + {{ part.name }}
{% trans %}id.label{% endtrans %}: {{ part.id }}
diff --git a/templates/show_part_info.html.twig b/templates/show_part_info.html.twig index b01d2a67..8d718148 100644 --- a/templates/show_part_info.html.twig +++ b/templates/show_part_info.html.twig @@ -23,7 +23,7 @@
{{ part.manufacturer.name ?? ""}}
-

{{ part.name }}

+

{{ part.name }}

{{ part.description }}