This repository was archived by the owner on May 2, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 6 files changed +116
-1
lines changed
DependencyInjection/Compiler Expand file tree Collapse file tree 6 files changed +116
-1
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ class ValueCompilerPass implements CompilerPassInterface
1313 *
1414 * Adds all tagged provider services to the provider pool
1515 *
16- * @param Symfony\Component\DependencyInjection\ ContainerBuilder $container
16+ * @param ContainerBuilder $container
1717 *
1818 * @return void
1919 */
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Opifer \EavBundle \Entity ;
4+
5+ use Doctrine \ORM \Mapping as ORM ;
6+
7+ /**
8+ * DateValue
9+ *
10+ * @ORM\Entity
11+ */
12+ class DateValue extends Value
13+ {
14+ /**
15+ * Turn value into string for form field value purposes
16+ *
17+ * @return string
18+ */
19+ public function __toString ()
20+ {
21+ return date ('d-m-Y ' , $ this ->getTimestamp ());
22+ }
23+
24+ /**
25+ * Get value
26+ *
27+ * @return \DateTime
28+ */
29+ public function getValue ()
30+ {
31+ $ datetime = new \DateTime ();
32+
33+ return $ datetime ->setTimestamp ($ this ->value );
34+ }
35+
36+ /**
37+ * Set value
38+ *
39+ * @param \DateTime $value
40+ *
41+ * @return DateTimeValue
42+ */
43+ public function setValue ($ value )
44+ {
45+ $ this ->value = $ value ->getTimestamp ();
46+
47+ return $ this ;
48+ }
49+
50+ /**
51+ * Get raw value
52+ *
53+ * @return string
54+ */
55+ public function getTimestamp ()
56+ {
57+ return $ this ->value ;
58+ }
59+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Opifer \EavBundle \Form \Type ;
4+
5+ use Symfony \Component \Form \AbstractType ;
6+ use Symfony \Component \OptionsResolver \OptionsResolver ;
7+
8+ class DatePickerType extends AbstractType
9+ {
10+ /**
11+ * {@inheritDoc}
12+ */
13+ public function configureOptions (OptionsResolver $ resolver )
14+ {
15+ $ resolver ->setDefaults ([
16+ 'widget ' => 'single_text ' ,
17+ 'format ' => 'yyyy-MM-dd ' ,
18+ 'attr ' => ['class ' => 'datepicker ' ]
19+ ]);
20+ }
21+
22+ /**
23+ * {@inheritDoc}
24+ */
25+ public function getParent ()
26+ {
27+ return 'date ' ;
28+ }
29+
30+ /**
31+ * {@inheritDoc}
32+ */
33+ public function getName ()
34+ {
35+ return 'opifer_eav_date_picker ' ;
36+ }
37+ }
Original file line number Diff line number Diff line change @@ -29,6 +29,11 @@ services:
2929 tags :
3030 - { name: opifer.eav.value_provider, alias: radio }
3131
32+ opifer.eav.date_value_provider :
33+ class : Opifer\EavBundle\ValueProvider\DateValueProvider
34+ tags :
35+ - { name: opifer.eav.value_provider, alias: date }
36+
3237 opifer.eav.datetime_value_provider :
3338 class : Opifer\EavBundle\ValueProvider\DatetimeValueProvider
3439 tags :
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ parameters:
44 opifer.eav.empty_value_listener.class : Opifer\EavBundle\EventListener\EmptyValueListener
55 opifer.eav.discriminator_listener.class : Opifer\EavBundle\EventListener\DiscriminatorListener
66 opifer.eav.form.attribute_type.class : Opifer\EavBundle\Form\Type\AttributeType
7+ opifer.eav.form.date_picker_type.class : Opifer\EavBundle\Form\Type\DatePickerType
78 opifer.eav.form.datetime_picker_type.class : Opifer\EavBundle\Form\Type\DateTimePickerType
89 opifer.eav.form.eav_type.class : Opifer\EavBundle\Form\Type\EavType
910 opifer.eav.form.eav_post_type.class : Opifer\EavBundle\Form\Type\EavPostType
@@ -37,6 +38,11 @@ services:
3738 tags :
3839 - { name: form.type, alias: eav_attribute }
3940
41+ opifer.eav.form.date_picker_type :
42+ class : %opifer.eav.form.date_picker_type.class%
43+ tags :
44+ - { name: form.type, alias: opifer_eav_date_picker }
45+
4046 opifer.eav.form.datetime_picker_type :
4147 class : %opifer.eav.form.datetime_picker_type.class%
4248 tags :
Original file line number Diff line number Diff line change @@ -26,4 +26,12 @@ public function getEntity()
2626 {
2727 return 'Opifer\EavBundle\Entity\DateValue ' ;
2828 }
29+
30+ /**
31+ * {@inheritDoc}
32+ */
33+ public function getLabel ()
34+ {
35+ return 'Date ' ;
36+ }
2937}
You can’t perform that action at this time.
0 commit comments