11
11
12
12
namespace simplygoodwork \donkeytail \fields ;
13
13
14
- // use simplygoodwork\donkeytail\Donkeytail;
15
14
use simplygoodwork \donkeytail \assetbundles \donkeytail \DonkeytailAsset ;
16
15
17
16
use Craft ;
20
19
use yii \db \Schema ;
21
20
use craft \helpers \Html ;
22
21
use craft \elements \Asset ;
23
- use craft \elements \Entry ;
24
- use craft \elements \Category ;
25
22
use craft \helpers \Json ;
26
23
use simplygoodwork \donkeytail \models \DonkeytailModel ;
27
24
use simplygoodwork \donkeytail \gql \DonkeytailType ;
@@ -44,23 +41,23 @@ class Donkeytail extends Field
44
41
// Public Properties
45
42
// =========================================================================
46
43
47
- public $ canvasSources = [];
44
+ public array $ canvasSources = [];
48
45
49
- public $ pinElementType = [] ;
46
+ public string $ pinElementType = '' ;
50
47
51
- public $ entrySources = [];
48
+ public array $ entrySources = [];
52
49
53
- public $ assetSources = [];
50
+ public array $ assetSources = [];
54
51
55
- public $ userSources = [];
52
+ public array $ userSources = [];
56
53
57
- public $ categorySources = [];
54
+ public array $ categorySources = [];
58
55
59
- public $ productSources = [];
56
+ public array $ productSources = [];
60
57
61
- public $ variantSources = [];
58
+ public array $ variantSources = [];
62
59
63
- public $ autoSelect = false ;
60
+ public bool $ autoSelect = false ;
64
61
65
62
// Static Methods
66
63
// =========================================================================
@@ -124,7 +121,7 @@ public function getContentColumnType(): array|string
124
121
*
125
122
* @return mixed The prepared field value
126
123
*/
127
- public function normalizeValue (mixed $ value , ?\ craft \ base \ ElementInterface $ element = null ): mixed
124
+ public function normalizeValue (mixed $ value , ?ElementInterface $ element = null ): mixed
128
125
{
129
126
$ site = ($ element ? $ element ->getSite () : Craft::$ app ->getSites ()->getCurrentSite ());
130
127
@@ -133,9 +130,12 @@ public function normalizeValue(mixed $value, ?\craft\base\ElementInterface $elem
133
130
}
134
131
135
132
$ value ['site ' ] = $ site ;
136
- $ model = new DonkeytailModel ($ value );
137
133
138
- return $ model ;
134
+ if ($ value instanceof DonkeytailModel){
135
+ return $ value ;
136
+ }
137
+
138
+ return new DonkeytailModel ($ value );
139
139
}
140
140
141
141
/**
@@ -265,7 +265,7 @@ public function getSettingsHtml(): ?string
265
265
}
266
266
267
267
// Render the settings template
268
- return Craft:: $ app -> getView () ->renderTemplate (
268
+ return $ view ->renderTemplate (
269
269
'donkeytail/_components/fields/Donkeytail_settings ' ,
270
270
[
271
271
'id ' => $ id ,
@@ -426,17 +426,17 @@ public function getInputHtml(mixed $value, ?\craft\base\ElementInterface $elemen
426
426
$ pinElement = Craft::$ app ->getElements ()->getElementById ($ pinId , $ pinElementType , $ site ->id );
427
427
if ($ pinElement ) {
428
428
// If element exists, show it
429
- array_push ( $ pinElements, $ pinElement) ;
429
+ $ pinElements[] = $ pinElement ;
430
430
431
431
// Ensure label for pin element is up to date
432
- if ($ this ->pinElementType == 'User ' ) {
432
+ if ($ this ->pinElementType === 'User ' ) {
433
433
$ value ->meta [$ pinElement ->id ]['label ' ] = $ pinElement ->username ;
434
434
} else {
435
435
$ value ->meta [$ pinElement ->id ]['label ' ] = $ pinElement ->title ;
436
436
}
437
437
438
438
// Only include meta for elements that exist
439
- array_push ( $ meta, $ value ->meta [$ pinElement ->id ]) ;
439
+ $ meta[] = $ value ->meta [$ pinElement ->id ];
440
440
}
441
441
}
442
442
}
@@ -456,13 +456,13 @@ public function getInputHtml(mixed $value, ?\craft\base\ElementInterface $elemen
456
456
'element ' => $ element ,
457
457
'site ' => $ site ->handle ,
458
458
459
- 'canvasSourceExists ' => count (Craft::$ app ->getAssets ()->findFolders ()),
459
+ 'canvasSourceExists ' => count (Craft::$ app ->getAssets ()->findFolders ([] )),
460
460
'canvasElements ' => $ canvasElements ,
461
461
'canvasElementType ' => Asset::class,
462
462
'canvasSources ' => $ this ->canvasSources ,
463
463
464
464
'pinElementType ' => $ pinElementType ,
465
- 'pinElementSources ' => $ this ->{$ pinElementSources } ? $ this ->{ $ pinElementSources } : null ,
465
+ 'pinElementSources ' => $ this ->{$ pinElementSources } ?: null ,
466
466
'pinElements ' => $ pinElements ,
467
467
468
468
'meta ' => json_encode ($ meta ),
0 commit comments