feat: using QRCode form

feat: using QRCode form

QROptionsDefaultProvider
This commit is contained in:
Ondrej Vlach 2024-01-16 20:31:08 +01:00
parent cb24d39930
commit 08a7d28065
Signed by: ovlach
GPG Key ID: 4FF1A23B4914DE70
3 changed files with 29 additions and 7 deletions

View File

@ -2,16 +2,37 @@
namespace App\Controller;
use App\Entity\QRCode\QRCode;
use App\Form\Type\QRCodeType;
use App\Service\QRCodeQROptionsProviderInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
class IndexController extends AbstractController {
#[Route('/', name: 'homepage')]
public function indexAction(): Response
public function indexAction(Request $request, QRCodeQROptionsProviderInterface $qrCodeQROptionsFactory): Response
{
$result = $this->render('index/homepage.html.twig');
return $result;
$qrCode = new QRCode(
codeQROptions: $qrCodeQROptionsFactory->getDefault()
);
$form = $this->createForm(QRCodeType::class, $qrCode);
if ($request->isMethod('POST')) {
$form->submit($request->request->all($form->getName()));
if ($form->isSubmitted() && $form->isValid()) {
// TODO: call service to generate
print_r($qrCode);
}
}
return $this->render('index/homepage.html.twig', [
'form' => $form
]);
}
}
}

View File

@ -5,8 +5,8 @@ namespace App\Service;
use App\Entity\QRCode\QRCodeQROptions;
readonly class QRCodeQROptionsDefaultProvider implements QRCodeQROptionsProviderInterface {
private readonly QRCodeQROptions $qrCodeDefaultOptions;
readonly final class QRCodeQROptionsDefaultProvider implements QRCodeQROptionsProviderInterface {
private QRCodeQROptions $qrCodeDefaultOptions;
public function __construct() {
$this->qrCodeDefaultOptions = new QRCodeQROptions(

View File

@ -2,4 +2,5 @@
{% block body %}
Homepage
{% endblock %}
{{ form(form) }}
{% endblock %}