3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+
6
7
namespace Magento \Ui \Component \Listing \Columns ;
7
8
9
+ use Magento \Framework \App \ObjectManager ;
10
+ use Magento \Framework \Locale \Bundle \DataBundle ;
11
+ use Magento \Framework \Locale \ResolverInterface ;
8
12
use Magento \Framework \Stdlib \BooleanUtils ;
9
13
use Magento \Framework \View \Element \UiComponent \ContextInterface ;
10
14
use Magento \Framework \View \Element \UiComponentFactory ;
@@ -28,11 +32,28 @@ class Date extends Column
28
32
*/
29
33
private $ booleanUtils ;
30
34
35
+ /**
36
+ * @var ResolverInterface
37
+ */
38
+ private $ localeResolver ;
39
+
40
+ /**
41
+ * @var string
42
+ */
43
+ private $ locale ;
44
+
45
+ /**
46
+ * @var DataBundle
47
+ */
48
+ private $ dataBundle ;
49
+
31
50
/**
32
51
* @param ContextInterface $context
33
52
* @param UiComponentFactory $uiComponentFactory
34
53
* @param TimezoneInterface $timezone
35
54
* @param BooleanUtils $booleanUtils
55
+ * @param ResolverInterface $localeResolver
56
+ * @param DataBundle $dataBundle
36
57
* @param array $components
37
58
* @param array $data
38
59
*/
@@ -41,11 +62,16 @@ public function __construct(
41
62
UiComponentFactory $ uiComponentFactory ,
42
63
TimezoneInterface $ timezone ,
43
64
BooleanUtils $ booleanUtils ,
65
+ ResolverInterface $ localeResolver = null ,
66
+ DataBundle $ dataBundle = null ,
44
67
array $ components = [],
45
68
array $ data = []
46
69
) {
47
70
$ this ->timezone = $ timezone ;
48
71
$ this ->booleanUtils = $ booleanUtils ;
72
+ $ this ->localeResolver = $ localeResolver ?? ObjectManager::getInstance ()->get (ResolverInterface::class);
73
+ $ this ->locale = $ this ->localeResolver ->getLocale ();
74
+ $ this ->dataBundle = $ dataBundle ?? ObjectManager::getInstance ()->get (DataBundle::class);
49
75
parent ::__construct ($ context , $ uiComponentFactory , $ components , $ data );
50
76
}
51
77
@@ -65,6 +91,25 @@ public function prepare()
65
91
]
66
92
]
67
93
];
94
+
95
+ $ localeData = $ this ->dataBundle ->get ($ this ->locale );
96
+ /** @var \ResourceBundle $monthsData */
97
+ $ monthsData = $ localeData ['calendar ' ]['gregorian ' ]['monthNames ' ];
98
+ $ months = array_values (iterator_to_array ($ monthsData ['format ' ]['wide ' ]));
99
+ $ monthsShort = array_values (
100
+ iterator_to_array (
101
+ null !== $ monthsData ->get ('format ' )->get ('abbreviated ' )
102
+ ? $ monthsData ['format ' ]['abbreviated ' ]
103
+ : $ monthsData ['format ' ]['wide ' ]
104
+ )
105
+ );
106
+
107
+ $ config ['storeLocale ' ] = $ this ->locale ;
108
+ $ config ['dateData ' ] = [
109
+ 'months ' => $ months ,
110
+ 'monthsShort ' => $ monthsShort ,
111
+ ];
112
+ $ config ['dateFormat ' ] = $ this ->timezone ->getDateTimeFormat (\IntlDateFormatter::MEDIUM );
68
113
$ this ->setData ('config ' , $ config );
69
114
70
115
parent ::prepare ();
@@ -78,7 +123,7 @@ public function prepareDataSource(array $dataSource)
78
123
if (isset ($ dataSource ['data ' ]['items ' ])) {
79
124
foreach ($ dataSource ['data ' ]['items ' ] as & $ item ) {
80
125
if (isset ($ item [$ this ->getData ('name ' )])
81
- && $ item [$ this ->getData ('name ' )] !== "0000-00-00 00:00:00 "
126
+ && $ item [$ this ->getData ('name ' )] !== "0000-00-00 00:00:00 "
82
127
) {
83
128
$ date = $ this ->timezone ->date (new \DateTime ($ item [$ this ->getData ('name ' )]));
84
129
$ timezone = isset ($ this ->getConfiguration ()['timezone ' ])
0 commit comments