Skip to content

Commit ad457e9

Browse files
author
Nicolas Debrigode
committed
save
1 parent d7b944f commit ad457e9

File tree

7 files changed

+98
-2
lines changed

7 files changed

+98
-2
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"symfony/property-access": "7.0.*",
2121
"symfony/runtime": "7.0.*",
2222
"symfony/twig-bundle": "7.0.*",
23+
"symfony/validator": "7.0.*",
2324
"symfony/yaml": "7.0.*",
2425
"twig/extra-bundle": "^3.0",
2526
"twig/string-extra": "^3.0",

config/packages/validator.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
framework:
2+
validation:
3+
# Enables validator auto-mapping support.
4+
# For instance, basic validation constraints will be inferred from Doctrine's metadata.
5+
#auto_mapping:
6+
# App\Entity\: []
7+
8+
when@test:
9+
framework:
10+
validation:
11+
not_compromised_password: false

src/Controller/BaseController.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
namespace App\Controller;
66

77
use App\Application\ConfigApplication;
8+
use App\Form\TopAsForm;
89
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
10+
use Symfony\Component\Form\FormView;
11+
use Symfony\Component\HttpFoundation\Request;
912
use Symfony\Component\HttpFoundation\RequestStack;
1013

1114
abstract class BaseController extends AbstractController
@@ -51,4 +54,12 @@ private function getBaseData(
5154
];
5255
}
5356
}
57+
58+
public function addFormTopAs(Request $request): FormView
59+
{
60+
$form = $this->createForm(TopAsForm::class);
61+
$form->handleRequest($request);
62+
63+
return $form->createView();
64+
}
5465
}

src/Controller/IndexController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public function index(
6868
'knownlinks' => KnowlinksRepository::get(),
6969
'form' => [
7070
'legend' => $form->createView(),
71+
'top' => $this->addFormTopAs($request),
7172
],
7273
]);
7374
}

src/Form/TopAsForm.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Form;
6+
7+
use Symfony\Component\Form\AbstractType;
8+
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
9+
use Symfony\Component\Form\FormBuilderInterface;
10+
use Symfony\Component\OptionsResolver\OptionsResolver;
11+
use Symfony\Component\Validator\Constraints\Range;
12+
13+
class TopAsForm extends AbstractType
14+
{
15+
/**
16+
* @param array<string, mixed> $options
17+
*/
18+
public function buildForm(FormBuilderInterface $builder, array $options): void
19+
{
20+
$builder
21+
->setMethod('get')
22+
->add('top', IntegerType::class, [
23+
'label' => false,
24+
'translation_domain' => false,
25+
'attr' => [
26+
'placeholder' => 'Top AS',
27+
],
28+
'constraints' => [
29+
new Range(
30+
notInRangeMessage: 'Value between {{ min }} and {{ max }}.',
31+
min: 1,
32+
max: 200
33+
),
34+
],
35+
]);
36+
}
37+
38+
public function getBlockPrefix(): string
39+
{
40+
return '';
41+
}
42+
43+
public function configureOptions(OptionsResolver $resolver): void
44+
{
45+
$resolver->setDefaults([
46+
'csrf_protection' => false,
47+
]);
48+
}
49+
}

symfony.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,18 @@
119119
"templates/base.html.twig"
120120
]
121121
},
122+
"symfony/validator": {
123+
"version": "7.0",
124+
"recipe": {
125+
"repo": "github.com/symfony/recipes",
126+
"branch": "main",
127+
"version": "7.0",
128+
"ref": "8c1c4e28d26a124b0bb273f537ca8ce443472bfd"
129+
},
130+
"files": [
131+
"config/packages/validator.yaml"
132+
]
133+
},
122134
"symfony/web-profiler-bundle": {
123135
"version": "7.0",
124136
"recipe": {

templates/base/_header.html.twig

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,25 @@
1111

1212
<div class="navbar-nav flex-row order-md-last">
1313
<div class="my-1 flex-grow-1 flex-md-grow-0 order-first">
14-
<form method="get" autocomplete="off" novalidate="">
14+
<!--<form method="get" autocomplete="off" novalidate="">
1515
<div class="input-icon">
1616
<span class="input-icon-addon">
1717
{{ icon('filter') }}
1818
</span>
1919
<input type="number" name='top' min=1 class="form-control" value="{{ base_data.request.top|default('') }}" placeholder="Top AS">
2020
</div>
21-
</form>
21+
</form>-->
22+
{% if form.top is defined %}
23+
{{ form_start(form.top) }}
24+
<div class="input-icon">
25+
<span class="input-icon-addon">
26+
{{ icon('filter') }}
27+
</span>
28+
{{ form_widget(form.top.top, {value: base_data.request.top|default('')}) }}
29+
</div>
30+
{{ form_errors(form.top.top) }}
31+
{{ form_end(form.top) }}
32+
{% endif %}
2233
</div>
2334
</div>
2435

0 commit comments

Comments
 (0)