1 | <?php |
||
2 | |||
3 | namespace LeKoala\FormElements; |
||
4 | |||
5 | use SilverStripe\Forms\LiteralField; |
||
6 | use SilverStripe\View\Requirements; |
||
7 | |||
8 | /** |
||
9 | */ |
||
10 | class FormatDateField extends LiteralField |
||
11 | { |
||
12 | use BaseElement; |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
13 | |||
14 | const FORMAT_ISO = "iso"; |
||
15 | const FORMAT_UTC = "utc"; |
||
16 | const FORMAT_DATETIME = "datetime"; |
||
17 | const FORMAT_DATE = "date"; |
||
18 | const FORMAT_TIME = "time"; |
||
19 | |||
20 | /** |
||
21 | * @config |
||
22 | * @var boolean |
||
23 | */ |
||
24 | private static $enable_requirements = true; |
||
25 | |||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $format = "iso"; |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $datestyle; |
||
35 | |||
36 | /** |
||
37 | * @var string |
||
38 | */ |
||
39 | protected $timestyle; |
||
40 | |||
41 | /** |
||
42 | * @var string |
||
43 | */ |
||
44 | protected $lang; |
||
45 | |||
46 | /** |
||
47 | * @param string $name |
||
48 | * @param string|FormField $content |
||
0 ignored issues
–
show
The type
LeKoala\FormElements\FormField was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
49 | * @param string $label |
||
50 | */ |
||
51 | public function __construct($name, $content = "", $title = null) |
||
52 | { |
||
53 | if ($content) { |
||
54 | $this->setContent($content); |
||
55 | } |
||
56 | if ($title) { |
||
57 | $this->setTitle($title); |
||
58 | } |
||
59 | |||
60 | parent::__construct($name, $content); |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * @param array $properties |
||
65 | * @return string |
||
66 | */ |
||
67 | public function FieldHolder($properties = array()) |
||
68 | { |
||
69 | if (self::config()->enable_requirements) { |
||
70 | self::requirements(); |
||
71 | } |
||
72 | |||
73 | $content = parent::FieldHolder($properties); |
||
74 | $attrsHTML = $this->getElementAttributesHTML(); |
||
75 | $content = "<format-date value=\"{$content}\" $attrsHTML></format-date>"; |
||
76 | |||
77 | if ($this->title) { |
||
78 | $content = "<span>{$this->title}</span> " . $content; |
||
79 | } |
||
80 | return $content; |
||
81 | } |
||
82 | |||
83 | public static function requirements() |
||
84 | { |
||
85 | Requirements::javascript("lekoala/silverstripe-form-elements: client/custom-elements/format-date.min.js"); |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * Get the value of format |
||
90 | */ |
||
91 | public function getFormat() |
||
92 | { |
||
93 | return $this->getElementAttribute('format'); |
||
94 | } |
||
95 | |||
96 | /** |
||
97 | * Set the value of format |
||
98 | * |
||
99 | * @param string $format |
||
100 | */ |
||
101 | public function setFormat($format) |
||
102 | { |
||
103 | return $this->setElementAttribute('format', $format); |
||
104 | } |
||
105 | |||
106 | /** |
||
107 | * Get the value of datestyle |
||
108 | */ |
||
109 | public function getDatestyle() |
||
110 | { |
||
111 | return $this->getElementAttribute('datestyle'); |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * Set the value of datestyle |
||
116 | * |
||
117 | * @param mixed $datestyle |
||
118 | */ |
||
119 | public function setDatestyle($datestyle) |
||
120 | { |
||
121 | return $this->setElementAttribute('datestyle', $datestyle); |
||
122 | } |
||
123 | |||
124 | /** |
||
125 | * Get the value of timestyle |
||
126 | */ |
||
127 | public function getTimestyle() |
||
128 | { |
||
129 | return $this->getElementAttribute('timestyle'); |
||
130 | } |
||
131 | |||
132 | /** |
||
133 | * Set the value of timestyle |
||
134 | * |
||
135 | * @param mixed $timestyle |
||
136 | */ |
||
137 | public function setTimestyle($timestyle) |
||
138 | { |
||
139 | return $this->setElementAttribute('timestyle', $timestyle); |
||
140 | } |
||
141 | |||
142 | /** |
||
143 | * Get the value of lang |
||
144 | */ |
||
145 | public function getLang() |
||
146 | { |
||
147 | return $this->getElementAttribute('lang'); |
||
148 | } |
||
149 | |||
150 | /** |
||
151 | * Set the value of lang |
||
152 | * |
||
153 | * @param mixed $lang |
||
154 | */ |
||
155 | public function setLang($lang) |
||
156 | { |
||
157 | return $this->setElementAttribute('lang', $lang); |
||
158 | } |
||
159 | } |
||
160 |