Skip to content

Commit ee85412

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

File tree

7 files changed

+73
-0
lines changed

7 files changed

+73
-0
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
}
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy