Skip to content

Commit 16be059

Browse files
committed
add type declarations
1 parent bf9ab3d commit 16be059

File tree

3 files changed

+26
-28
lines changed

3 files changed

+26
-28
lines changed

src/fields/Donkeytail.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace simplygoodwork\donkeytail\fields;
1313

14-
// use simplygoodwork\donkeytail\Donkeytail;
1514
use simplygoodwork\donkeytail\assetbundles\donkeytail\DonkeytailAsset;
1615

1716
use Craft;
@@ -20,8 +19,6 @@
2019
use yii\db\Schema;
2120
use craft\helpers\Html;
2221
use craft\elements\Asset;
23-
use craft\elements\Entry;
24-
use craft\elements\Category;
2522
use craft\helpers\Json;
2623
use simplygoodwork\donkeytail\models\DonkeytailModel;
2724
use simplygoodwork\donkeytail\gql\DonkeytailType;
@@ -44,23 +41,23 @@ class Donkeytail extends Field
4441
// Public Properties
4542
// =========================================================================
4643

47-
public $canvasSources = [];
44+
public array $canvasSources = [];
4845

49-
public $pinElementType = [];
46+
public string $pinElementType = '';
5047

51-
public $entrySources = [];
48+
public array $entrySources = [];
5249

53-
public $assetSources = [];
50+
public array $assetSources = [];
5451

55-
public $userSources = [];
52+
public array $userSources = [];
5653

57-
public $categorySources = [];
54+
public array $categorySources = [];
5855

59-
public $productSources = [];
56+
public array $productSources = [];
6057

61-
public $variantSources = [];
58+
public array $variantSources = [];
6259

63-
public $autoSelect = false;
60+
public bool $autoSelect = false;
6461

6562
// Static Methods
6663
// =========================================================================
@@ -124,7 +121,7 @@ public function getContentColumnType(): array|string
124121
*
125122
* @return mixed The prepared field value
126123
*/
127-
public function normalizeValue(mixed $value, ?\craft\base\ElementInterface $element = null): mixed
124+
public function normalizeValue(mixed $value, ?ElementInterface $element = null): mixed
128125
{
129126
$site = ($element ? $element->getSite() : Craft::$app->getSites()->getCurrentSite());
130127

@@ -133,9 +130,12 @@ public function normalizeValue(mixed $value, ?\craft\base\ElementInterface $elem
133130
}
134131

135132
$value['site'] = $site;
136-
$model = new DonkeytailModel($value);
137133

138-
return $model;
134+
if($value instanceof DonkeytailModel){
135+
return $value;
136+
}
137+
138+
return new DonkeytailModel($value);
139139
}
140140

141141
/**
@@ -265,7 +265,7 @@ public function getSettingsHtml(): ?string
265265
}
266266

267267
// Render the settings template
268-
return Craft::$app->getView()->renderTemplate(
268+
return $view->renderTemplate(
269269
'donkeytail/_components/fields/Donkeytail_settings',
270270
[
271271
'id' => $id,
@@ -426,17 +426,17 @@ public function getInputHtml(mixed $value, ?\craft\base\ElementInterface $elemen
426426
$pinElement = Craft::$app->getElements()->getElementById($pinId, $pinElementType, $site->id);
427427
if ($pinElement) {
428428
// If element exists, show it
429-
array_push($pinElements, $pinElement);
429+
$pinElements[] = $pinElement;
430430

431431
// Ensure label for pin element is up to date
432-
if ($this->pinElementType == 'User') {
432+
if ($this->pinElementType === 'User') {
433433
$value->meta[$pinElement->id]['label'] = $pinElement->username;
434434
} else {
435435
$value->meta[$pinElement->id]['label'] = $pinElement->title;
436436
}
437437

438438
// Only include meta for elements that exist
439-
array_push($meta, $value->meta[$pinElement->id]);
439+
$meta[] = $value->meta[$pinElement->id];
440440
}
441441
}
442442
}
@@ -456,13 +456,13 @@ public function getInputHtml(mixed $value, ?\craft\base\ElementInterface $elemen
456456
'element' => $element,
457457
'site' => $site->handle,
458458

459-
'canvasSourceExists' => count(Craft::$app->getAssets()->findFolders()),
459+
'canvasSourceExists' => count(Craft::$app->getAssets()->findFolders([])),
460460
'canvasElements' => $canvasElements,
461461
'canvasElementType' => Asset::class,
462462
'canvasSources' => $this->canvasSources,
463463

464464
'pinElementType' => $pinElementType,
465-
'pinElementSources' => $this->{$pinElementSources} ? $this->{$pinElementSources} : null,
465+
'pinElementSources' => $this->{$pinElementSources} ?: null,
466466
'pinElements' => $pinElements,
467467

468468
'meta' => json_encode($meta),

src/models/DonkeytailModel.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,9 @@
1111

1212
namespace simplygoodwork\donkeytail\models;
1313

14-
use simplygoodwork\donkeytail\Donkeytail;
15-
1614
use Craft;
1715
use craft\base\Model;
1816
use craft\services\Elements;
19-
use craft\elements\Entry;
20-
use simplygoodwork\donkeytail\models\PinModel;
2117

2218
/**
2319
* DonkeytailModel Model
@@ -30,6 +26,10 @@
3026
* @author Good Work
3127
* @package Donkeytail
3228
* @since 1.0.0
29+
*
30+
* @property-read null|object $canvas
31+
* @property-read array $pins
32+
* @property-read null $pinsElementType
3333
*/
3434
class DonkeytailModel extends Model
3535
{
@@ -80,7 +80,7 @@ class DonkeytailModel extends Model
8080
public function rules(): array
8181
{
8282
return [
83-
['canvasId', 'array'],
83+
['canvasId', 'string'],
8484
['pinIds', 'array'],
8585
['meta', 'array'],
8686
];

src/templates/_components/fields/Donkeytail_input.twig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
elementType: canvasElementType,
3737
criteria: {
3838
'kind': [],
39-
'enabledForSite': null,
4039
'site': site
4140
},
4241
sources: canvasSources,
@@ -65,7 +64,6 @@
6564
label: 'Pins' |t,
6665
elementType: pinElementType,
6766
criteria: {
68-
'enabledForSite': null,
6967
'site': site
7068
},
7169
sources: pinElementSources,

0 commit comments

Comments
 (0)