Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Date.php
Go to the documentation of this file.
1 <?php
7 
12 {
19  protected function _toHtml()
20  {
21  $html = '<input type="text" name="' . $this->getName() . '" id="' . $this->getId() . '" ';
22  $html .= 'value="' . $this->escapeHtml($this->getValue()) . '" ';
23  $html .= 'class="' . $this->getClass() . '" ' . $this->getExtraParams() . '/> ';
24  $calendarYearsRange = $this->getYearsRange();
25  $changeMonth = $this->getChangeMonth();
26  $changeYear = $this->getChangeYear();
27  $maxDate = $this->getMaxDate();
28  $showOn = $this->getShowOn();
29  $firstDay = $this->getFirstDay();
30 
31  $html .= '<script type="text/javascript">
32  require(["jquery", "mage/calendar"], function($){
33  $("#' .
34  $this->getId() .
35  '").calendar({
36  showsTime: ' .
37  ($this->getTimeFormat() ? 'true' : 'false') .
38  ',
39  ' .
40  ($this->getTimeFormat() ? 'timeFormat: "' .
41  $this->getTimeFormat() .
42  '",' : '') .
43  '
44  dateFormat: "' .
45  $this->getDateFormat() .
46  '",
47  buttonImage: "' .
48  $this->getImage() .
49  '",
50  ' .
51  ($calendarYearsRange ? 'yearRange: "' .
52  $calendarYearsRange .
53  '",' : '') .
54  '
55  buttonText: "' .
56  (string)new \Magento\Framework\Phrase(
57  'Select Date'
58  ) .
59  '"' . ($maxDate ? ', maxDate: "' . $maxDate . '"' : '') .
60  ($changeMonth === null ? '' : ', changeMonth: ' . $changeMonth) .
61  ($changeYear === null ? '' : ', changeYear: ' . $changeYear) .
62  ($showOn ? ', showOn: "' . $showOn . '"' : '') .
63  ($firstDay ? ', firstDay: ' . $firstDay : '') .
64  '})
65  });
66  </script>';
67 
68  return $html;
69  }
70 
76  public function getEscapedValue()
77  {
78  if ($this->getFormat() && $this->getValue()) {
79  return strftime($this->getFormat(), strtotime($this->getValue()));
80  }
81  return htmlspecialchars($this->getValue());
82  }
83 
91  public function getHtml()
92  {
93  return $this->toHtml();
94  }
95 }