Skip to content

Commit 3ab54d3

Browse files
ISSUE-22: Implemented BirthdayType
1 parent 26f3016 commit 3ab54d3

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

src/BirthdayType.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
/**
3+
* Copyright (c) 2017 DarkWeb Design
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18+
* SOFTWARE.
19+
*/
20+
21+
namespace DarkWebDesign\SymfonyAddon\FormType;
22+
23+
use Symfony\Component\Form\AbstractType;
24+
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
25+
26+
/**
27+
* Birthday form field type.
28+
*
29+
* @author Raymond Schouten
30+
*
31+
* @since 2.3
32+
*/
33+
class BirthdayType extends AbstractType
34+
{
35+
/**
36+
* Sets the default options for this type.
37+
*
38+
* @param \Symfony\Component\OptionsResolver\OptionsResolverInterface $resolver
39+
*/
40+
public function setDefaultOptions(OptionsResolverInterface $resolver)
41+
{
42+
$resolver->setDefaults(array(
43+
'years' => range(date('Y'), date('Y') - 120),
44+
));
45+
}
46+
47+
/**
48+
* Returns the name of the parent type.
49+
*
50+
* @return string
51+
*/
52+
public function getParent()
53+
{
54+
return 'date';
55+
}
56+
57+
/**
58+
* Returns the name of this type.
59+
*
60+
* @return string
61+
*/
62+
public function getName()
63+
{
64+
return 'birthday';
65+
}
66+
}

0 commit comments

Comments
 (0)