File tree Expand file tree Collapse file tree 3 files changed +74
-28
lines changed
app/code/Magento/Cms/Model Expand file tree Collapse file tree 3 files changed +74
-28
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Copyright © Magento, Inc. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
6
+ namespace Magento \Cms \Model \Config \Source ;
7
+
8
+ use Magento \Cms \Model \ResourceModel \Block \CollectionFactory ;
9
+
10
+ /**
11
+ * Class Block
12
+ */
13
+ class Block implements \Magento \Framework \Option \ArrayInterface
14
+ {
15
+ /**
16
+ * @var array
17
+ */
18
+ private $ options ;
19
+
20
+ /**
21
+ * @var CollectionFactory
22
+ */
23
+ private $ collectionFactory ;
24
+
25
+ /**
26
+ * @param CollectionFactory $collectionFactory
27
+ */
28
+ public function __construct (
29
+ CollectionFactory $ collectionFactory
30
+ ) {
31
+ $ this ->collectionFactory = $ collectionFactory ;
32
+ }
33
+
34
+ /**
35
+ * To option array
36
+ *
37
+ * @return array
38
+ */
39
+ public function toOptionArray ()
40
+ {
41
+ if (!$ this ->options ) {
42
+ $ this ->options = $ this ->collectionFactory ->create ()->toOptionIdArray ();
43
+ }
44
+ return $ this ->options ;
45
+ }
46
+ }
Original file line number Diff line number Diff line change @@ -176,4 +176,32 @@ public function getSelectCountSql()
176
176
177
177
return $ countSelect ;
178
178
}
179
+
180
+ /**
181
+ * Returns pairs identifier - title for unique identifiers
182
+ * and pairs identifier|entity_id - title for non-unique after first
183
+ *
184
+ * @return array
185
+ */
186
+ public function toOptionIdArray ()
187
+ {
188
+ $ res = [];
189
+ $ existingIdentifiers = [];
190
+ foreach ($ this as $ item ) {
191
+ $ identifier = $ item ->getData ('identifier ' );
192
+
193
+ $ data ['value ' ] = $ identifier ;
194
+ $ data ['label ' ] = $ item ->getData ('title ' );
195
+
196
+ if (in_array ($ identifier , $ existingIdentifiers )) {
197
+ $ data ['value ' ] .= '| ' . $ item ->getData ($ this ->getIdFieldName ());
198
+ } else {
199
+ $ existingIdentifiers [] = $ identifier ;
200
+ }
201
+
202
+ $ res [] = $ data ;
203
+ }
204
+
205
+ return $ res ;
206
+ }
179
207
}
Original file line number Diff line number Diff line change @@ -51,34 +51,6 @@ protected function _construct()
51
51
$ this ->_map ['fields ' ]['store ' ] = 'store_table.store_id ' ;
52
52
}
53
53
54
- /**
55
- * Returns pairs identifier - title for unique identifiers
56
- * and pairs identifier|page_id - title for non-unique after first
57
- *
58
- * @return array
59
- */
60
- public function toOptionIdArray ()
61
- {
62
- $ res = [];
63
- $ existingIdentifiers = [];
64
- foreach ($ this as $ item ) {
65
- $ identifier = $ item ->getData ('identifier ' );
66
-
67
- $ data ['value ' ] = $ identifier ;
68
- $ data ['label ' ] = $ item ->getData ('title ' );
69
-
70
- if (in_array ($ identifier , $ existingIdentifiers )) {
71
- $ data ['value ' ] .= '| ' . $ item ->getData ('page_id ' );
72
- } else {
73
- $ existingIdentifiers [] = $ identifier ;
74
- }
75
-
76
- $ res [] = $ data ;
77
- }
78
-
79
- return $ res ;
80
- }
81
-
82
54
/**
83
55
* Set first store flag
84
56
*
You can’t perform that action at this time.
0 commit comments