1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Framework\View\Element\Html;
- /**
- * Date element block
- */
- class Date extends \Magento\Framework\View\Element\Template
- {
- /**
- * Render block HTML
- *
- * @return string
- * @SuppressWarnings(PHPMD.NPathComplexity)
- */
- protected function _toHtml()
- {
- $html = '<input type="text" name="' . $this->getName() . '" id="' . $this->getId() . '" ';
- $html .= 'value="' . $this->escapeHtml($this->getValue()) . '" ';
- $html .= 'class="' . $this->getClass() . '" ' . $this->getExtraParams() . '/> ';
- $calendarYearsRange = $this->getYearsRange();
- $changeMonth = $this->getChangeMonth();
- $changeYear = $this->getChangeYear();
- $maxDate = $this->getMaxDate();
- $showOn = $this->getShowOn();
- $firstDay = $this->getFirstDay();
- $html .= '<script type="text/javascript">
- require(["jquery", "mage/calendar"], function($){
- $("#' .
- $this->getId() .
- '").calendar({
- showsTime: ' .
- ($this->getTimeFormat() ? 'true' : 'false') .
- ',
- ' .
- ($this->getTimeFormat() ? 'timeFormat: "' .
- $this->getTimeFormat() .
- '",' : '') .
- '
- dateFormat: "' .
- $this->getDateFormat() .
- '",
- buttonImage: "' .
- $this->getImage() .
- '",
- ' .
- ($calendarYearsRange ? 'yearRange: "' .
- $calendarYearsRange .
- '",' : '') .
- '
- buttonText: "' .
- (string)new \Magento\Framework\Phrase(
- 'Select Date'
- ) .
- '"' . ($maxDate ? ', maxDate: "' . $maxDate . '"' : '') .
- ($changeMonth === null ? '' : ', changeMonth: ' . $changeMonth) .
- ($changeYear === null ? '' : ', changeYear: ' . $changeYear) .
- ($showOn ? ', showOn: "' . $showOn . '"' : '') .
- ($firstDay ? ', firstDay: ' . $firstDay : '') .
- '})
- });
- </script>';
- return $html;
- }
- /**
- * Convert special characters to HTML entities
- *
- * @return string
- */
- public function getEscapedValue()
- {
- if ($this->getFormat() && $this->getValue()) {
- return strftime($this->getFormat(), strtotime($this->getValue()));
- }
- return htmlspecialchars($this->getValue());
- }
- /**
- * Produce and return block's html output
- *
- * {@inheritdoc}
- *
- * @return string
- */
- public function getHtml()
- {
- return $this->toHtml();
- }
- }
|