8000 Add new Form WeekType · symfony/symfony@4eb5bec · GitHub
[go: up one dir, main page]

Skip to content

Commit 4eb5bec

Browse files
author
dFayet
committed
Add new Form WeekType
1 parent 19811b8 commit 4eb5bec

File tree

8 files changed

+74
-1
lines changed

8 files changed

+74
-1
lines changed

src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,11 @@
255255
{{ block('form_widget_simple') }}
256256
{%- endblock color_widget -%}
257257

258+
{%- block week_widget -%}
259+
{%- set type = type|default('week') -%}
260+
{{ block('form_widget_simple') }}
261+
{%- endblock week_widget -%}
262+
258263
{# Labels #}
259264

260265
{%- block form_label -%}

src/Symfony/Bridge/Twig/Tests/Extension/AbstractBootstrap3LayoutTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2719,6 +2719,21 @@ public function testColor()
27192719
[@name="name"]
27202720
[@class="my&class form-control"]
27212721
[@value="#0000ff"]
2722+
'
2723+
);
2724+
}
2725+
2726+
public function testWeek()
2727+
{
2728+
$form = $this->factory->createNamed('holidays', 'Symfony\Component\Form\Extension\Core\Type\WeekType', '1970-W01');
2729+
2730+
$this->assertWidgetMatchesXpath($form->createView(), ['attr' => ['class' => 'my&class']],
2731+
'/input
2732+
[@type="week"]
2733+
[@name="holidays"]
2734+
[@class="my&class form-control"]
2735+
[@value="1970-W01"]
2736+
[not(@maxlength)]
27222737
'
27232738
);
27242739
}

src/Symfony/Bridge/Twig/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"symfony/asset": "^3.4|^4.0|^5.0",
2525
"symfony/dependency-injection": "^3.4|^4.0|^5.0",
2626
"symfony/finder": "^3.4|^4.0|^5.0",
27-
"symfony/form": "^4.3|^5.0",
27+
"symfony/form": "^4.4|^5.0",
2828
"symfony/http-foundation": "^4.3|^5.0",
2929
"symfony/http-kernel": "^3.4|^4.0|^5.0",
3030
"symfony/mime": "^4.3|^5.0",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php echo $view['form']->block($form, 'form_widget_simple', ['type' => isset($type) ? $type : 'week']);

src/Symfony/Component/Form/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
CHANGELOG
22
=========
33

4+
4.3.0
5+
-----
6+
* add new `WeekType`
7+
48
4.3.0
59
-----
610

src/Symfony/Component/Form/Extension/Core/CoreExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ protected function loadTypes()
8383
new Type\CurrencyType(),
8484
new Type\TelType(),
8585
new Type\ColorType(),
86+
new Type\WeekType(),
8687
];
8788
}
8889

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Form\Extension\Core\Type;
13+
14+
use Symfony\Component\Form\AbstractType;
15+
16+
class WeekType extends AbstractType
17+
{
18+
/**
19+
* {@inheritdoc}
20+
*/
21+
public function getParent()
22+
{
23+
return TextType::class;
24+
}
25+
26+
/**
27+
* {@inheritdoc}
28+
*/
29+
public function getBlockPrefix()
30+
{
31+
return 'week';
32+
}
33+
}

src/Symfony/Component/Form/Tests/AbstractLayoutTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2716,6 +2716,20 @@ public function testButtonWithTranslationParameters()
27162716
$this->assertMatchesXpath($html,
27172717
'/button
27182718
[.="[trans]Submit to ACME Ltd.[/trans]"]
2719+
'
2720+
);
2721+
}
2722+
2723+
public function testWeek()
2724+
{
2725+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\WeekType', '1970-W01');
2726+
2727+
$this->assertWidgetMatchesXpath($form->createView(), [],
2728+
'/input
2729+
[@type="week"]
2730+
[@name="name"]
2731+
[@value="1970-W01"]
2732+
[not(@maxlength)]
27192733
'
27202734
);
27212735
}

0 commit comments

Comments
 (0)
0