Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
YtdStart.php
Go to the documentation of this file.
1 <?php
7 
9 
15 class YtdStart extends \Magento\Config\Block\System\Config\Form\Field
16 {
23  {
24  $_months = [];
25  for ($i = 1; $i <= 12; $i++) {
26  $_months[$i] = $this->_localeDate->date(mktime(null, null, null, $i, 1))->format('m');
27  }
28  $_days = [];
29  for ($i = 1; $i <= 31; $i++) {
30  $_days[$i] = $i < 10 ? '0' . $i : $i;
31  }
32 
33  if ($element->getValue()) {
34  $values = explode(',', $element->getValue());
35  } else {
36  $values = [];
37  }
38 
39  $element->setName($element->getName() . '[]');
40 
41  $_monthsHtml = $element->setStyle(
42  'width:100px;'
43  )->setValues(
44  $_months
45  )->setValue(
46  isset($values[0]) ? $values[0] : null
47  )->getElementHtml();
48 
49  $_daysHtml = $element->setStyle(
50  'width:50px;'
51  )->setValues(
52  $_days
53  )->setValue(
54  isset($values[1]) ? $values[1] : null
55  )->getElementHtml();
56 
57  return sprintf('%s %s', $_monthsHtml, $_daysHtml);
58  }
59 }
$values
Definition: options.phtml:88
$i
Definition: gallery.phtml:31
$element
Definition: element.phtml:12