3
3
namespace Drupal \data_dictionary_widget \Indexes ;
4
4
5
5
/**
6
- * Various operations for creating Data Dictionary Widget fields .
6
+ * Various operations for index widget buttons .
7
7
*/
8
8
class IndexFieldButtons {
9
9
@@ -25,7 +25,7 @@ public static function addIndexFieldButton() {
25
25
],
26
26
'#ajax ' => [
27
27
'callback ' => '\Drupal\data_dictionary_widget\Indexes\IndexFieldCallbacks::subIndexFormAjax ' ,
28
- 'wrapper ' => 'field-json-metadata-dictionary- index-fields ' ,
28
+ 'wrapper ' => 'field-json-metadata-index-fields ' ,
29
29
'effect ' => 'fade ' ,
30
30
],
31
31
'#limit_validation_errors ' => [],
@@ -50,7 +50,7 @@ public static function addIndexButton() {
50
50
],
51
51
'#ajax ' => [
52
52
'callback ' => '\Drupal\data_dictionary_widget\Indexes\IndexFieldCallbacks::indexFormAjax ' ,
53
- 'wrapper ' => 'field-json-metadata-dictionary- index ' ,
53
+ 'wrapper ' => 'field-json-metadata-index ' ,
54
54
'effect ' => 'fade ' ,
55
55
],
56
56
'#limit_validation_errors ' => [],
@@ -61,10 +61,19 @@ public static function addIndexButton() {
61
61
* Returns the edit buttons.
62
62
*/
63
63
public static function editIndexButtons ($ indexKey ) {
64
+ if (str_contains ($ indexKey , 'field ' )) {
65
+ $ callback = 'indexEditSubformCallback ' ;
66
+ $ id = 'field-json-metadata-index-fields ' ;
67
+ $ function = 'subIndexFormAjax ' ;
68
+ } else {
69
+ $ callback = 'indexEditCallback ' ;
70
+ $ id = 'field-json-metadata-index ' ;
71
+ $ function = 'indexFormAjax ' ;
72
+ }
64
73
return [
65
74
'#type ' => 'image_button ' ,
66
- '#name ' => 'edit_index_ ' . $ indexKey ,
67
- '#id ' => 'edit_index_ ' . $ indexKey ,
75
+ '#name ' => 'edit_ ' . $ indexKey ,
76
+ '#id ' => 'edit_ ' . $ indexKey ,
68
77
'#access ' => TRUE ,
69
78
'#op ' => 'edit_ ' . $ indexKey ,
70
79
'#src ' => 'core/misc/icons/787878/cog.svg ' ,
@@ -75,12 +84,12 @@ public static function editIndexButtons($indexKey) {
75
84
'#submit ' => [
76
85
[
77
86
'\Drupal\data_dictionary_widget\Indexes\IndexFieldCallbacks ' ,
78
- ' indexEditSubformCallback ' ,
87
+ $ callback ,
79
88
],
80
89
],
81
90
'#ajax ' => [
82
- 'callback ' => '\Drupal\data_dictionary_widget\Indexes\IndexFieldCallbacks::subIndexFormAjax ' ,
83
- 'wrapper ' => ' field-json-metadata-dictionary-index-fields ' ,
91
+ 'callback ' => '\Drupal\data_dictionary_widget\Indexes\IndexFieldCallbacks:: ' . $ function ,
92
+ 'wrapper ' => $ id ,
84
93
'effect ' => 'fade ' ,
85
94
],
86
95
'#limit_validation_errors ' => [
@@ -96,6 +105,7 @@ public static function submitIndexFieldButton($location, $indexKey) {
96
105
$ callbackClass = $ location == 'edit ' ? 'indexEditSubformCallback ' : 'indexAddSubformCallback ' ;
97
106
$ op = !empty ($ indexKey ) ? 'update_ ' . $ indexKey : 'add_index_field ' ;
98
107
$ value = $ location == 'edit ' ? 'Save ' : 'Add ' ;
108
+ $ function = $ location == 'edit ' ? 'subIndexFormAjax ' : 'subIndexFormAjax ' ;
99
109
$ edit_index_button = [
100
110
'#type ' => 'submit ' ,
101
111
'#value ' => $ value ,
@@ -107,8 +117,8 @@ public static function submitIndexFieldButton($location, $indexKey) {
107
117
],
108
118
],
109
119
'#ajax ' => [
110
- 'callback ' => 'Drupal\data_dictionary_widget\Indexes\IndexFieldCallbacks::subIndexFormAjax ' ,
111
- 'wrapper ' => 'field-json-metadata-dictionary- index-fields ' ,
120
+ 'callback ' => 'Drupal\data_dictionary_widget\Indexes\IndexFieldCallbacks:: ' . $ function ,
121
+ 'wrapper ' => 'field-json-metadata-index-fields ' ,
112
122
'effect ' => 'fade ' ,
113
123
],
114
124
'#limit_validation_errors ' => [
@@ -151,7 +161,7 @@ public static function submitIndexButton($location, $indexKey) {
151
161
],
152
162
'#ajax ' => [
153
163
'callback ' => 'Drupal\data_dictionary_widget\Indexes\IndexFieldCallbacks::indexFormAjax ' ,
154
- 'wrapper ' => 'field-json-metadata-dictionary- index ' ,
164
+ 'wrapper ' => 'field-json-metadata-index ' ,
155
165
'effect ' => 'fade ' ,
156
166
],
157
167
'#limit_validation_errors ' => [
@@ -170,7 +180,7 @@ public static function submitIndexButton($location, $indexKey) {
170
180
* Create Cancel button.
171
181
*/
172
182
public static function cancelIndexFieldButton ($ location , $ indexKey , $ id ) {
173
- $ callbackId = ($ id === 'field-json-metadata-dictionary- index-fields-new ' ) ? 'subIndexFormExistingFieldAjax ' : 'subIndexFormAjax ' ;
183
+ $ callbackId = ($ id === 'field-json-metadata-index-fields-new ' ) ? 'subIndexFormExistingFieldAjax ' : 'subIndexFormAjax ' ;
174
184
$ callbackClass = $ location == 'edit ' ? 'indexEditSubformCallback ' : 'indexAddSubformCallback ' ;
175
185
$ op = $ location == 'edit ' && $ indexKey ? 'abort_ ' . $ indexKey : 'cancel_index_field ' ;
176
186
$ cancel_index_button = [
@@ -217,7 +227,7 @@ public static function cancelIndexButton($location, $indexKey) {
217
227
],
218
228
'#ajax ' => [
219
229
'callback ' => 'Drupal\data_dictionary_widget\Indexes\IndexFieldCallbacks::indexFormAjax ' ,
220
- 'wrapper ' => 'field-json-metadata-dictionary- index ' ,
230
+ 'wrapper ' => 'field-json-metadata-index ' ,
221
231
'effect ' => 'fade ' ,
222
232
],
223
233
'#limit_validation_errors ' => [],
@@ -232,7 +242,7 @@ public static function cancelIndexButton($location, $indexKey) {
232
242
/**
233
243
* Create Delete button.
234
244
*/
235
- public static function deleteIndexButton ($ indexKey ) {
245
+ public static function deleteIndexFieldButton ($ indexKey ) {
236
246
return [
237
247
'#type ' => 'submit ' ,
238
248
'#name ' => 'index_delete_ ' . $ indexKey ,
@@ -246,7 +256,31 @@ public static function deleteIndexButton($indexKey) {
246
256
],
247
257
'#ajax ' => [
248
258
'callback ' => 'Drupal\data_dictionary_widget\Indexes\IndexFieldCallbacks::subIndexFormAjax ' ,
249
- 'wrapper ' => 'field-json-metadata-dictionary-index-fields ' ,
259
+ 'wrapper ' => 'field-json-metadata-index-fields ' ,
260
+ 'effect ' => 'fade ' ,
261
+ ],
262
+ '#limit_validation_errors ' => [],
263
+ ];
264
+ }
265
+
266
+ /**
267
+ * Create Delete button.
268
+ */
269
+ public static function deleteIndexButton ($ indexKey ) {
270
+ return [
271
+ '#type ' => 'submit ' ,
272
+ '#name ' => 'index_delete_ ' . $ indexKey ,
273
+ '#value ' => t ('Delete index ' ),
274
+ '#op ' => 'delete_ ' . $ indexKey ,
275
+ '#submit ' => [
276
+ [
277
+ '\Drupal\data_dictionary_widget\Indexes\IndexFieldCallbacks ' ,
278
+ 'indexEditCallback ' ,
279
+ ],
280
+ ],
281
+ '#ajax ' => [
282
+ 'callback ' => 'Drupal\data_dictionary_widget\Indexes\IndexFieldCallbacks::indexFormAjax ' ,
283
+ 'wrapper ' => 'field-json-metadata-index ' ,
250
284
'effect ' => 'fade ' ,
251
285
],
252
286
'#limit_validation_errors ' => [],
0 commit comments