@@ -107,6 +107,9 @@ public function getFields(): array
107107 foreach ($ tableColumns as $ tableColumn ) {
108108 $ columnName = $ tableColumn ['COLUMN_NAME ' ];
109109 $ fieldTypeCode = $ this ->getFieldTypeCodeFromColumn ($ tableColumn );
110+ $ fieldLabel = $ this ->getLabelByColumn ($ tableColumn ['COLUMN_NAME ' ]);
111+ $ sortOrder = 0 ;
112+
110113 if (empty ($ fieldTypeCode )) {
111114 // @todo: echo 'Unknown field type: '.$tableColumn['DATA_TYPE'];
112115 continue ;
@@ -117,8 +120,17 @@ public function getFields(): array
117120
118121 if (array_key_exists ($ columnName , $ fieldDefinitions )) {
119122 $ fieldDefinition = (array )$ fieldDefinitions [$ columnName ];
123+
120124 if (isset ($ fieldDefinition ['field_type ' ])) {
121- $ fieldTypeCode = $ fieldDefinition ['field_type ' ];
125+ $ fieldTypeCode = (string )$ fieldDefinition ['field_type ' ];
126+ }
127+
128+ if (isset ($ fieldDefinition ['label ' ])) {
129+ $ fieldLabel = (string )$ fieldDefinition ['label ' ];
130+ }
131+
132+ if (isset ($ fieldDefinition ['sortOrder ' ])) {
133+ $ sortOrder = (int )$ fieldDefinition ['sortOrder ' ];
122134 }
123135
124136 if (isset ($ fieldDefinition ['html_attributes ' ])) {
@@ -131,13 +143,18 @@ public function getFields(): array
131143 $ fields [] = $ this ->fieldFactory ->create (
132144 $ block ,
133145 $ fieldTypeCode ,
134- $ this -> getLabelByColumn ( $ tableColumn [ ' COLUMN_NAME ' ]) ,
146+ $ fieldLabel ,
135147 $ tableColumn ['COLUMN_NAME ' ],
136148 false , // @todo
137- $ htmlAttributes
149+ $ htmlAttributes ,
150+ $ sortOrder
138151 );
139152 }
140153
154+ usort ($ fields , function (Field $ field1 , Field $ field2 ) {
155+ return $ field1 ->getSortOrder () <=> $ field2 ->getSortOrder ();
156+ });
157+
141158 return $ fields ;
142159 }
143160
@@ -181,7 +198,8 @@ private function getIndexUri(): string
181198 $ currentUri = (string )$ this ->request ->getParam ('currentUri ' );
182199 if (!empty ($ currentUri )) {
183200 $ currentUriParts = explode ('_ ' , $ currentUri );
184- return $ currentUriParts [0 ] . '/ ' . $ currentUriParts [1 ] . '/index ' ;
201+
202+ return $ currentUriParts [0 ].'/ ' .$ currentUriParts [1 ].'/index ' ;
185203 }
186204
187205 return '*/*/index ' ;
0 commit comments