2 declare(strict_types = 1);
58 parent::initializeArguments();
59 $this->registerTagAttribute(
'size',
'int',
'The size of the select field');
60 $this->registerTagAttribute(
'placeholder',
'string',
'Specifies a short hint that describes the expected value of an input element');
61 $this->registerTagAttribute(
'disabled',
'string',
'Specifies that the select element should be disabled when the page loads');
62 $this->registerArgument(
'errorClass',
'string',
'CSS class to set if there are errors for this ViewHelper',
false,
'f3-form-error');
63 $this->registerArgument(
'initialDate',
'string',
'Initial time (@see http://www.php.net/manual/en/datetime.formats.php for supported formats)');
64 $this->registerArgument(
'timeType',
'string',
'"hour" or "minute"');
65 $this->registerUniversalTagAttributes();
77 $this->tag->addAttribute(
'name', $name .
'[hour]');
84 if ($this->arguments[
'timeType'] ===
'hour') {
99 $formRuntime = $this->renderingContext
100 ->getViewHelperVariableContainer()
101 ->get(RenderRenderableViewHelper::class,
'formRuntime');
103 $date = $formRuntime[$this->arguments[
'property']];
104 if ($date instanceof \DateTime) {
107 if ($date !==
null) {
108 $date = $this->propertyMapper->convert($date,
'DateTime');
109 if (!$date instanceof \DateTime) {
114 if ($this->hasArgument(
'initialDate')) {
115 return new \DateTime($this->arguments[
'initialDate']);
125 $value = $date !==
null ? $date->format(
'H') :
null;
126 $hourSelector = clone $this->tag;
127 $hourSelector->addAttribute(
'name', sprintf(
'%s[hour]', $this->
getName()));
129 foreach (range(0, 23) as $hour) {
130 $hour = str_pad((
string)$hour, 2,
'0', STR_PAD_LEFT);
131 $selected = $hour === $value ?
' selected="selected"' :
'';
132 $options .=
'<option value="' . htmlspecialchars($hour) .
'" ' . $selected .
'>' . htmlspecialchars($hour) .
'</option>';
134 $hourSelector->setContent($options);
135 return $hourSelector->render();
144 $value = $date !==
null ? $date->format(
'i') :
null;
145 $minuteSelector = clone $this->tag;
146 if ($this->hasArgument(
'id')) {
147 $minuteSelector->addAttribute(
'id', $this->arguments[
'id'] .
'-minute');
149 $minuteSelector->addAttribute(
'name', sprintf(
'%s[minute]', $this->
getName()));
151 foreach (range(0, 59) as $minute) {
152 $minute = str_pad((
string)$minute, 2,
'0', STR_PAD_LEFT);
153 $selected = $minute === $value ?
' selected="selected"' :
'';
154 $options .=
'<option value="' . htmlspecialchars($minute) .
'"' . $selected .
'>' . htmlspecialchars($minute) .
'</option>';
156 $minuteSelector->setContent($options);
157 return $minuteSelector->render();