|
1
|
+<?php |
|
2
|
+ |
|
3
|
+ namespace backend\widgets; |
|
4
|
+ |
|
5
|
+ use artbox\core\admin\assets\DateRangePicker; |
|
6
|
+ use artbox\core\admin\assets\Switchery; |
|
7
|
+ use artbox\core\admin\widgets\ImageInput; |
|
8
|
+ use artbox\core\helpers\SlugifyDecorator; |
|
9
|
+ use artbox\core\models\Language; |
|
10
|
+ use artbox\core\services\Languages; |
|
11
|
+ use artbox\core\widgets\GalleryWidget; |
|
12
|
+ use function call_user_func; |
|
13
|
+ use dosamigos\tinymce\TinyMce; |
|
14
|
+ use kartik\select2\Select2; |
|
15
|
+ use mihaildev\ckeditor\CKEditor; |
|
16
|
+ use yii\base\InvalidConfigException; |
|
17
|
+ use yii\base\Widget; |
|
18
|
+ use yii\db\ActiveRecord; |
|
19
|
+ use yii\helpers\ArrayHelper; |
|
20
|
+ use yii\helpers\Html; |
|
21
|
+ use yii\widgets\ActiveForm; |
|
22
|
+ |
|
23
|
+ /** |
|
24
|
+ * Render inputs to create or save ActiveRecord model with all relational models |
|
25
|
+ * |
|
26
|
+ * @package artbox\core\admin\widgets |
|
27
|
+ */ |
|
28
|
+ class Form extends Widget |
|
29
|
+ { |
|
30
|
+ /** |
|
31
|
+ * Generates WYSIWYG redactor |
|
32
|
+ * |
|
33
|
+ * @see TinyMce, https://www.tinymce.com/ |
|
34
|
+ */ |
|
35
|
+ const WYSIWYG = 'wysiwyg'; |
|
36
|
+ |
|
37
|
+ /** |
|
38
|
+ * Generates text input |
|
39
|
+ */ |
|
40
|
+ const STRING = 'string'; |
|
41
|
+ |
|
42
|
+ /** |
|
43
|
+ * Generates textarea |
|
44
|
+ */ |
|
45
|
+ const TEXTAREA = 'textarea'; |
|
46
|
+ |
|
47
|
+ /** |
|
48
|
+ * Generates checkbox |
|
49
|
+ */ |
|
50
|
+ const BOOL = 'boolean'; |
|
51
|
+ |
|
52
|
+ /** |
|
53
|
+ * Generates simple number input type |
|
54
|
+ */ |
|
55
|
+ const NUMBER = 'number'; |
|
56
|
+ |
|
57
|
+ /** |
|
58
|
+ * Generates select2 widget |
|
59
|
+ */ |
|
60
|
+ const RELATION = 'relation'; |
|
61
|
+ |
|
62
|
+ /** |
|
63
|
+ * Generates one image input |
|
64
|
+ */ |
|
65
|
+ const IMAGE = 'image'; |
|
66
|
+ |
|
67
|
+ /** |
|
68
|
+ * Generates Gallery widget |
|
69
|
+ * |
|
70
|
+ * @see GalleryWidget, \artbox\core\behaviors\GalleryBehavior |
|
71
|
+ */ |
|
72
|
+ const GALLERY = 'gallery'; |
|
73
|
+ |
|
74
|
+ /** |
|
75
|
+ * |
|
76
|
+ */ |
|
77
|
+ const DATE = 'date'; |
|
78
|
+ |
|
79
|
+ /** |
|
80
|
+ * generate select |
|
81
|
+ */ |
|
82
|
+ const SELECT = 'select'; |
|
83
|
+ /** |
|
84
|
+ * @var \artbox\core\admin\actions\Save |
|
85
|
+ */ |
|
86
|
+ public $action; |
|
87
|
+ |
|
88
|
+ /** |
|
89
|
+ * @var Languages |
|
90
|
+ */ |
|
91
|
+ protected $languages; |
|
92
|
+ |
|
93
|
+ /** |
|
94
|
+ * @var \yii\db\ActiveRecord |
|
95
|
+ */ |
|
96
|
+ public $model; |
|
97
|
+ |
|
98
|
+ /** |
|
99
|
+ * Template for 1 language tab |
|
100
|
+ * |
|
101
|
+ * @var string |
|
102
|
+ */ |
|
103
|
+ public $langTabTemplate = '<div class="style tabs-lang" style="display: {display};"><div class="style title-edit-page">{title}</div>{tab}</div>'; |
|
104
|
+ |
|
105
|
+ /** |
|
106
|
+ * Template for block of all languages tabs |
|
107
|
+ * |
|
108
|
+ * @var string |
|
109
|
+ */ |
|
110
|
+ public $langBlockTemplate = '<div class="x_panel x_panel-scroll tabs-lang-wr">{tabs}</div>'; |
|
111
|
+ /** |
|
112
|
+ * @var array fields for seo value |
|
113
|
+ */ |
|
114
|
+ public $decorateField = []; |
|
115
|
+ /** |
|
116
|
+ * @inheritdoc |
|
117
|
+ * @todo Remove H1 stabs |
|
118
|
+ * @return string|void |
|
119
|
+ * @throws \Exception |
|
120
|
+ * @throws \yii\base\InvalidConfigException |
|
121
|
+ */ |
|
122
|
+ public function run() |
|
123
|
+ { |
|
124
|
+ Switchery::register($this->view); |
|
125
|
+ |
|
126
|
+ $js = <<< JS |
|
127
|
+$('.switchery').each(function(idx, elem) { |
|
128
|
+ new Switchery(elem, { |
|
129
|
+ color:'#46b749', |
|
130
|
+ secondaryColor:'#e2e2e2' |
|
131
|
+ }); |
|
132
|
+}); |
|
133
|
+JS; |
|
134
|
+ |
|
135
|
+ |
|
136
|
+ $this->languages = new Languages(); |
|
137
|
+ |
|
138
|
+ $this->view->registerJs($js, \yii\web\View::POS_READY); |
|
139
|
+ $notify = <<<JS |
|
140
|
+ $('form').on('afterValidate', function(form, attribute, messages){ |
|
141
|
+ if (messages.length > 0){ |
|
142
|
+ new PNotify({ |
|
143
|
+ title: 'Info', |
|
144
|
+ text: 'Проверьте заполнение полей', |
|
145
|
+ type: 'info', |
|
146
|
+ styling: "bootstrap3" |
|
147
|
+ }); |
|
148
|
+ } |
|
149
|
+ }); |
|
150
|
+JS; |
|
151
|
+ |
|
152
|
+ $this->view->registerJs($notify, \yii\web\View::POS_READY); |
|
153
|
+ |
|
154
|
+ $form = ActiveForm::begin(); |
|
155
|
+ if (!empty($this->action->languageFields)) { |
|
156
|
+ echo str_replace( |
|
157
|
+ [ |
|
158
|
+ '{tabs}', |
|
159
|
+ '{title}', |
|
160
|
+ ], |
|
161
|
+ [ |
|
162
|
+ $this->generateLangBlock($form), |
|
163
|
+ 'Языковой блок', |
|
164
|
+ ], |
|
165
|
+ $this->langBlockTemplate |
|
166
|
+ ); |
|
167
|
+ } |
|
168
|
+ |
|
169
|
+ echo '<div class="x_panel x_panel-scroll">'; |
|
170
|
+ |
|
171
|
+ echo '<div class="wrapp-blocks-edit-page columns-2">'; |
|
172
|
+ echo '<div class="style title-edit-page">Основной блок</div>'; |
|
173
|
+ $this->generateCommonBlock($form); |
|
174
|
+ echo '</div>'; |
|
175
|
+ |
|
176
|
+ echo '</div>'; |
|
177
|
+ |
|
178
|
+ if ($this->action->hasAlias) { |
|
179
|
+ echo str_replace( |
|
180
|
+ [ |
|
181
|
+ '{tabs}', |
|
182
|
+ '{title}', |
|
183
|
+ ], |
|
184
|
+ [ |
|
185
|
+ $this->generateAliasBlock($form), |
|
186
|
+ 'Seo блок', |
|
187
|
+ ], |
|
188
|
+ $this->langBlockTemplate |
|
189
|
+ ); |
|
190
|
+ } |
|
191
|
+ |
|
192
|
+ if ($this->action->hasGallery) { |
|
193
|
+ echo '<div class="x_panel x_panel-scroll">'; |
|
194
|
+ echo '<div class="wrapp-blocks-edit-page">'; |
|
195
|
+ echo '<div class="style title-edit-page">Галерея</div>'; |
|
196
|
+ echo GalleryWidget::widget( |
|
197
|
+ [ |
|
198
|
+ 'model' => $this->model, |
|
199
|
+ ] |
|
200
|
+ ); |
|
201
|
+ echo '</div>'; |
|
202
|
+ echo '</div>'; |
|
203
|
+ } |
|
204
|
+ |
|
205
|
+ echo '<div class="style buttons-page-wr">'; |
|
206
|
+ echo Html::submitButton( |
|
207
|
+ \Yii::t('core', 'Save'), |
|
208
|
+ [ |
|
209
|
+ 'class' => 'btn btn-success', |
|
210
|
+ ] |
|
211
|
+ ); |
|
212
|
+ echo '</div>'; |
|
213
|
+ |
|
214
|
+ $form::end(); |
|
215
|
+ |
|
216
|
+ $this->registerClientScripts(); |
|
217
|
+ } |
|
218
|
+ |
|
219
|
+ protected function registerClientScripts() |
|
220
|
+ { |
|
221
|
+ $js = <<<JS |
|
222
|
+ $(document) |
|
223
|
+ .on('click', '.pos-minus-adm', function(e) { |
|
224
|
+ e.preventDefault(); |
|
225
|
+ var input = $(this) |
|
226
|
+ .parent() |
|
227
|
+ .find('input'); |
|
228
|
+ var newVal = parseInt(input.val()) - 1; |
|
229
|
+ if (newVal > 0) { |
|
230
|
+ input.val(newVal); |
|
231
|
+ } |
|
232
|
+ }); |
|
233
|
+ $(document) |
|
234
|
+ .on('click', '.pos-pluse-adm', function(e) { |
|
235
|
+ e.preventDefault(); |
|
236
|
+ var input = $(this) |
|
237
|
+ .parent() |
|
238
|
+ .find('input'); |
|
239
|
+ var newVal = parseInt((input.val() === '' ? 0 : input.val())) + 1; |
|
240
|
+ input.val(newVal); |
|
241
|
+ }); |
|
242
|
+ |
|
243
|
+ $('#page-sort').keypress(function(e) { |
|
244
|
+ var symbol = (e.which) ? e.which : e.keyCode; |
|
245
|
+ if (symbol < 48 || symbol > 57) { |
|
246
|
+ return false; |
|
247
|
+ } |
|
248
|
+ }) |
|
249
|
+JS; |
|
250
|
+ |
|
251
|
+ $this->view->registerJs($js, \yii\web\View::POS_READY); |
|
252
|
+ } |
|
253
|
+ |
|
254
|
+ /** |
|
255
|
+ * If model has languages |
|
256
|
+ * |
|
257
|
+ * @param \yii\widgets\ActiveForm $form |
|
258
|
+ * |
|
259
|
+ * @return string |
|
260
|
+ * @throws \yii\base\InvalidConfigException |
|
261
|
+ */ |
|
262
|
+ protected function generateLangBlock(ActiveForm $form): string |
|
263
|
+ { |
|
264
|
+ $tabs = ''; |
|
265
|
+ $i = 1; |
|
266
|
+ foreach ($this->getVariationModels() as $index => $variationModel) { |
|
267
|
+ $tab = ''; |
|
268
|
+ foreach ($this->action->languageFields as $languageField) { |
|
269
|
+ switch ($languageField[ 'type' ]) { |
|
270
|
+ case self::STRING: |
|
271
|
+ if (isset($languageField[ 'decorate' ]) and $languageField[ 'decorate' ]) { |
|
272
|
+ $this->decorateField[ $index ] = $form->field( |
|
273
|
+ $variationModel, |
|
274
|
+ '[' . $index . ']' . $languageField[ 'name' ] |
|
275
|
+ ) |
|
276
|
+ ->label( |
|
277
|
+ self::getLanguageLabel( |
|
278
|
+ $variationModel, |
|
279
|
+ $languageField[ 'name' ], |
|
280
|
+ $variationModel->language_id |
|
281
|
+ ) |
|
282
|
+ ); |
|
283
|
+ $tab .= $this->decorateField[ $index ]; |
|
284
|
+ } else { |
|
285
|
+ $tab .= $form->field($variationModel, '[' . $index . ']' . $languageField[ 'name' ]) |
|
286
|
+ ->label( |
|
287
|
+ self::getLanguageLabel( |
|
288
|
+ $variationModel, |
|
289
|
+ $languageField[ 'name' ], |
|
290
|
+ $variationModel->language_id |
|
291
|
+ ) |
|
292
|
+ ); |
|
293
|
+ } |
|
294
|
+ break; |
|
295
|
+ case self::TEXTAREA: |
|
296
|
+ $tab .= $form->field($variationModel, '[' . $index . ']' . $languageField[ 'name' ]) |
|
297
|
+ ->textarea( |
|
298
|
+ [ |
|
299
|
+ 'rows' => 6, |
|
300
|
+ ] |
|
301
|
+ ) |
|
302
|
+ ->label( |
|
303
|
+ self::getLanguageLabel( |
|
304
|
+ $variationModel, |
|
305
|
+ $languageField[ 'name' ], |
|
306
|
+ $variationModel->language_id |
|
307
|
+ ) |
|
308
|
+ ); |
|
309
|
+ break; |
|
310
|
+ case self::IMAGE: |
|
311
|
+ $tab .= $form->field( |
|
312
|
+ $variationModel, |
|
313
|
+ '[' . $index . ']' . $languageField[ 'name' ], |
|
314
|
+ [ 'options' => [ 'class' => 'form-group filed-upload-imgs' ] ] |
|
315
|
+ ) |
|
316
|
+ ->widget( |
|
317
|
+ ImageInput::className(), |
|
318
|
+ [ |
|
319
|
+ 'showPreview' => true, |
|
320
|
+ ] |
|
321
|
+ ) |
|
322
|
+ ->label( |
|
323
|
+ self::getLanguageLabel( |
|
324
|
+ $variationModel, |
|
325
|
+ $languageField[ 'name' ], |
|
326
|
+ $variationModel->language_id |
|
327
|
+ ) |
|
328
|
+ ); |
|
329
|
+ break; |
|
330
|
+ case self::WYSIWYG: |
|
331
|
+ $tab .= $form->field($variationModel, '[' . $index . ']' . $languageField[ 'name' ]) |
|
332
|
+ ->widget( |
|
333
|
+ TinyMce::className(), |
|
334
|
+ $this->action->getTinyMceConfig() |
|
335
|
+ ) |
|
336
|
+ ->label( |
|
337
|
+ self::getLanguageLabel( |
|
338
|
+ $variationModel, |
|
339
|
+ $languageField[ 'name' ], |
|
340
|
+ $variationModel->language_id |
|
341
|
+ ) |
|
342
|
+ ); |
|
343
|
+ break; |
|
344
|
+ default: |
|
345
|
+ throw new InvalidConfigException( |
|
346
|
+ \Yii::t( |
|
347
|
+ 'core', |
|
348
|
+ 'Unavailable or unknown type: {type}', |
|
349
|
+ [ |
|
350
|
+ 'type' => $languageField[ 'type' ], |
|
351
|
+ ] |
|
352
|
+ ) |
|
353
|
+ ); |
|
354
|
+ } |
|
355
|
+ } |
|
356
|
+ |
|
357
|
+ if ($variationModel->language_id === $this->languages->getDefault()->id) { |
|
358
|
+ $tabs .= str_replace( |
|
359
|
+ [ |
|
360
|
+ '{tab}', |
|
361
|
+ '{display}', |
|
362
|
+ ], |
|
363
|
+ [ |
|
364
|
+ $tab, |
|
365
|
+ 'block', |
|
366
|
+ ], |
|
367
|
+ $this->langTabTemplate |
|
368
|
+ ); |
|
369
|
+ } else { |
|
370
|
+ $tabs .= str_replace( |
|
371
|
+ [ |
|
372
|
+ '{tab}', |
|
373
|
+ '{display}', |
|
374
|
+ ], |
|
375
|
+ [ |
|
376
|
+ $tab, |
|
377
|
+ 'none', |
|
378
|
+ ], |
|
379
|
+ $this->langTabTemplate |
|
380
|
+ ); |
|
381
|
+ } |
|
382
|
+ |
|
383
|
+ $i++; |
|
384
|
+ } |
|
385
|
+ |
|
386
|
+ return $tabs; |
|
387
|
+ } |
|
388
|
+ |
|
389
|
+ /** |
|
390
|
+ * Common block |
|
391
|
+ * |
|
392
|
+ * @param \yii\widgets\ActiveForm $form |
|
393
|
+ * |
|
394
|
+ * @throws \yii\base\InvalidConfigException |
|
395
|
+ */ |
|
396
|
+ protected function generateCommonBlock(ActiveForm $form) |
|
397
|
+ { |
|
398
|
+ foreach ($this->action->fields as $field) { |
|
399
|
+ switch ($field[ 'type' ]) { |
|
400
|
+ case self::STRING: |
|
401
|
+ echo $form->field($this->model, $field[ 'name' ]); |
|
402
|
+ break; |
|
403
|
+ case self::TEXTAREA: |
|
404
|
+ echo $form->field($this->model, $field[ 'name' ]) |
|
405
|
+ ->textarea( |
|
406
|
+ [ |
|
407
|
+ 'rows' => 6, |
|
408
|
+ ] |
|
409
|
+ ); |
|
410
|
+ break; |
|
411
|
+ case self::WYSIWYG: |
|
412
|
+ echo $form->field($this->model, $field[ 'name' ]) |
|
413
|
+ ->widget( |
|
414
|
+ TinyMce::className(), |
|
415
|
+ $this->action->getTinyMceConfig() |
|
416
|
+ ); |
|
417
|
+ break; |
|
418
|
+ case self::BOOL: |
|
419
|
+ echo $form->field( |
|
420
|
+ $this->model, |
|
421
|
+ $field[ 'name' ], |
|
422
|
+ [ |
|
423
|
+ 'template' => "<div class='div_ style' style='margin-bottom: 10px;'>{label}</div>\n{input}\n{error}", |
|
424
|
+ ] |
|
425
|
+ ) |
|
426
|
+ ->checkbox( |
|
427
|
+ [ |
|
428
|
+ 'class' => 'switchery', |
|
429
|
+ ], |
|
430
|
+ false |
|
431
|
+ ); |
|
432
|
+ break; |
|
433
|
+ case self::NUMBER: |
|
434
|
+ echo $form->field( |
|
435
|
+ $this->model, |
|
436
|
+ $field[ 'name' ], |
|
437
|
+ [ |
|
438
|
+ 'template' => '{label}<span class="pos-minus-adm"></span>{input}<span class="pos-pluse-adm"></span> |
|
439
|
+ {error}{hint}', |
|
440
|
+ 'options' => [ 'class' => 'form-group filed-sort' ], |
|
441
|
+ ] |
|
442
|
+ ); |
|
443
|
+ break; |
|
444
|
+ case self::RELATION: |
|
445
|
+ $isMultiple = $field[ 'multiple' ] ?? false; |
|
446
|
+ echo $form->field($this->model, $field[ 'name' ]) |
|
447
|
+ ->widget( |
|
448
|
+ Select2::classname(), |
|
449
|
+ [ |
|
450
|
+ 'data' => $this->action->relationalData[ $field[ 'name' ] ], |
|
451
|
+ 'options' => [ |
|
452
|
+ 'placeholder' => \Yii::t('core', 'Select ...'), |
|
453
|
+ 'multiple' => $isMultiple, |
|
454
|
+ ], |
|
455
|
+ 'pluginOptions' => [ |
|
456
|
+ 'allowClear' => true, |
|
457
|
+ ], |
|
458
|
+ ] |
|
459
|
+ ); |
|
460
|
+ break; |
|
461
|
+ case self::SELECT: |
|
462
|
+ $isMultiple = $field[ 'multiple' ] ?? false; |
|
463
|
+ echo $form->field($this->model, $field[ 'name' ]) |
|
464
|
+ ->widget( |
|
465
|
+ Select2::classname(), |
|
466
|
+ [ |
|
467
|
+ 'data' => $field['data'], |
|
468
|
+ 'options' => [ |
|
469
|
+ 'placeholder' => \Yii::t('core', 'Select ...'), |
|
470
|
+ 'multiple' => $isMultiple, |
|
471
|
+ ], |
|
472
|
+ 'pluginOptions' => [ |
|
473
|
+ 'allowClear' => true, |
|
474
|
+ ], |
|
475
|
+ ] |
|
476
|
+ ); |
|
477
|
+ |
|
478
|
+ break; |
|
479
|
+ case self::IMAGE: |
|
480
|
+ echo $form->field( |
|
481
|
+ $this->model, |
|
482
|
+ $field[ 'name' ], |
|
483
|
+ [ 'options' => [ 'class' => 'form-group filed-upload-imgs' ] ] |
|
484
|
+ ) |
|
485
|
+ ->widget( |
|
486
|
+ ImageInput::className(), |
|
487
|
+ [ |
|
488
|
+ 'showPreview' => true, |
|
489
|
+ ] |
|
490
|
+ ); |
|
491
|
+ break; |
|
492
|
+ case self::DATE: |
|
493
|
+ DateRangePicker::register($this->view); |
|
494
|
+ $mindate = date("d-m-Y H:i"); |
|
495
|
+ $value = $this->model->{$field['name']}; |
|
496
|
+ $js = <<< JS |
|
497
|
+var dateRangeInputFrom = $('#date_field'); |
|
498
|
+var dateFormat = '{$this->model->clientDateFormat}'; |
|
499
|
+dateRangeInputFrom.daterangepicker({ |
|
500
|
+ singleDatePicker: true, |
|
501
|
+ autoUpdateInput: true, |
|
502
|
+ showDropdowns: true, |
|
503
|
+ minDate: '{$mindate}', |
|
504
|
+ timePicker: true, |
|
505
|
+ timePicker24Hour: true, |
|
506
|
+ locale: { |
|
507
|
+ cancelLabel: 'Clear', |
|
508
|
+ format: dateFormat |
|
509
|
+ } |
|
510
|
+}, function(){ |
|
511
|
+ |
|
512
|
+ }); |
|
513
|
+dateRangeInputFrom.on('cancel.daterangepicker', function(ev, picker) { |
|
514
|
+ //do something, like clearing an input |
|
515
|
+ dateRangeInputFrom.val(''); |
|
516
|
+}); |
|
517
|
+if ("{$value}" == ""){ |
|
518
|
+ dateRangeInputFrom.val(''); |
|
519
|
+} |
|
520
|
+JS; |
|
521
|
+ $this->view->registerJs($js, \yii\web\View::POS_READY); |
|
522
|
+ echo $form->field( |
|
523
|
+ $this->model, |
|
524
|
+ $field[ 'name' ], |
|
525
|
+ [ 'options' => [ 'class' => 'form-group date-search' ] ] |
|
526
|
+ )->textInput(['id' => "date_field"]); |
|
527
|
+ break; |
|
528
|
+ |
|
529
|
+ default: |
|
530
|
+ throw new InvalidConfigException( |
|
531
|
+ \Yii::t( |
|
532
|
+ 'core', |
|
533
|
+ 'Unavailable or unknown type: {type}', |
|
534
|
+ [ |
|
535
|
+ 'type' => $field[ 'type' ], |
|
536
|
+ ] |
|
537
|
+ ) |
|
538
|
+ ); |
|
539
|
+ } |
|
540
|
+ } |
|
541
|
+ } |
|
542
|
+ |
|
543
|
+ /** |
|
544
|
+ * Generate seo block |
|
545
|
+ * |
|
546
|
+ * @param \yii\widgets\ActiveForm $form |
|
547
|
+ * |
|
548
|
+ * @return string |
|
549
|
+ */ |
|
550
|
+ protected function generateAliasBlock(ActiveForm $form) |
|
551
|
+ { |
|
552
|
+ $tabs = ''; |
|
553
|
+ $i = 1; |
|
554
|
+ foreach ($this->getAliases() as $index => $alias) { |
|
555
|
+ $tab = ''; |
|
556
|
+ if (isset($this->decorateField[ $index ])) { |
|
557
|
+ $tab .= '<div class="seo-btns-wr">' . SlugifyDecorator::decorate( |
|
558
|
+ $form->field($alias, "[$index]value"), |
|
559
|
+ [ '/seo/alias/slugify' ], |
|
560
|
+ $this->decorateField[ $index ], |
|
561
|
+ false, |
|
562
|
+ $alias->language_id |
|
563
|
+ ) |
|
564
|
+ ->textInput( |
|
565
|
+ [ 'maxlength' => true ] |
|
566
|
+ ) . "</div>"; |
|
567
|
+ } else { |
|
568
|
+ $tab .= $form->field($alias, '[' . $index . ']value') |
|
569
|
+ ->label( |
|
570
|
+ self::getLanguageLabel($alias, 'value', $alias->language_id) |
|
571
|
+ ); |
|
572
|
+ } |
|
573
|
+ |
|
574
|
+ $tab .= $form->field($alias, '[' . $index . ']title') |
|
575
|
+ ->label( |
|
576
|
+ self::getLanguageLabel($alias, 'title', $alias->language_id) |
|
577
|
+ ); |
|
578
|
+ |
|
579
|
+ $tab .= $form->field($alias, '[' . $index . ']description') |
|
580
|
+ ->textarea( |
|
581
|
+ [ |
|
582
|
+ 'rows' => 6, |
|
583
|
+ ] |
|
584
|
+ ) |
|
585
|
+ ->label( |
|
586
|
+ self::getLanguageLabel($alias, 'description', $alias->language_id) |
|
587
|
+ ); |
|
588
|
+ |
|
589
|
+ $tab .= $form->field($alias, '[' . $index . ']h1') |
|
590
|
+ ->label( |
|
591
|
+ self::getLanguageLabel($alias, 'h1', $alias->language_id) |
|
592
|
+ ); |
|
593
|
+ |
|
594
|
+ $tab .= $form->field($alias, '[' . $index . ']seo_text') |
|
595
|
+ ->widget( |
|
596
|
+ TinyMce::className(), |
|
597
|
+ $this->action->getTinyMceConfig() |
|
598
|
+ ) |
|
599
|
+ ->label( |
|
600
|
+ self::getLanguageLabel($alias, 'seo_text', $alias->language_id) |
|
601
|
+ ); |
|
602
|
+ |
|
603
|
+ $tab .= $form->field($alias, '[' . $index . ']robots') |
|
604
|
+ ->widget( |
|
605
|
+ Select2::class, |
|
606
|
+ [ |
|
607
|
+ 'data' => [ |
|
608
|
+ 'index, follow' => 'index, follow', |
|
609
|
+ 'index, nofollow' => 'index, nofollow', |
|
610
|
+ 'noindex, follow' => 'noindex, follow', |
|
611
|
+ 'noindex, nofollow' => 'noindex, nofollow', |
|
612
|
+ ], |
|
613
|
+ ] |
|
614
|
+ ) |
|
615
|
+ ->label( |
|
616
|
+ self::getLanguageLabel($alias, 'robots', $alias->language_id) |
|
617
|
+ ); |
|
618
|
+ |
|
619
|
+ if ($alias->language_id === $this->languages->getDefault()->id) { |
|
620
|
+ $tabs .= str_replace( |
|
621
|
+ [ |
|
622
|
+ '{tab}', |
|
623
|
+ '{display}', |
|
624
|
+ ], |
|
625
|
+ [ |
|
626
|
+ $tab, |
|
627
|
+ 'block', |
|
628
|
+ ], |
|
629
|
+ $this->langTabTemplate |
|
630
|
+ ); |
|
631
|
+ } else { |
|
632
|
+ $tabs .= str_replace( |
|
633
|
+ [ |
|
634
|
+ '{tab}', |
|
635
|
+ '{display}', |
|
636
|
+ ], |
|
637
|
+ [ |
|
638
|
+ $tab, |
|
639
|
+ 'none', |
|
640
|
+ ], |
|
641
|
+ $this->langTabTemplate |
|
642
|
+ ); |
|
643
|
+ } |
|
644
|
+ |
|
645
|
+ $i++; |
|
646
|
+ } |
|
647
|
+ |
|
648
|
+ return $tabs; |
|
649
|
+ } |
|
650
|
+ |
|
651
|
+ /** |
|
652
|
+ * Appends language short name to label |
|
653
|
+ * |
|
654
|
+ * @param \yii\db\ActiveRecord $model |
|
655
|
+ * @param string $field |
|
656
|
+ * @param $language_id |
|
657
|
+ * |
|
658
|
+ * @return string |
|
659
|
+ */ |
|
660
|
+ protected static function getLanguageLabel(ActiveRecord $model, string $field, $language_id): string |
|
661
|
+ { |
|
662
|
+ $languages = Language::getActive(); |
|
663
|
+ return $model->getAttributeLabel( |
|
664
|
+ $field |
|
665
|
+ ) . ' (' . $languages[ $language_id ]->url . ')'; |
|
666
|
+ |
|
667
|
+ } |
|
668
|
+ |
|
669
|
+ /** |
|
670
|
+ * @return ActiveRecord[] |
|
671
|
+ */ |
|
672
|
+ protected function getVariationModels(): array |
|
673
|
+ { |
|
674
|
+ return call_user_func( |
|
675
|
+ [ |
|
676
|
+ $this->model, |
|
677
|
+ 'getVariationModels', |
|
678
|
+ ] |
|
679
|
+ ); |
|
680
|
+ } |
|
681
|
+ |
|
682
|
+ /** |
|
683
|
+ * @return \artbox\core\models\Alias[] |
|
684
|
+ */ |
|
685
|
+ protected function getAliases(): array |
|
686
|
+ { |
|
687
|
+ return call_user_func( |
|
688
|
+ [ |
|
689
|
+ $this->model, |
|
690
|
+ 'loadAliases', |
|
691
|
+ ] |
|
692
|
+ ); |
|
693
|
+ } |
|
694
|
+ } |
|
695
|
+ |
|
696
|
+?> |
|
697
|
+ |
|
698
|
+ |
|
699
|
+ |
...
|
...
|
|