diff --git a/CHANGELOG.MD b/CHANGELOG.MD index eddbb73..e022cdc 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -1,5 +1,9 @@ # Release Notes for LinkMate +## 2.2.2 - 2022-08-02 +### Fixed +- Fixes typing issues in ElementSourceValidator + ## 2.2.1 - 2022-05-02 ### Fixed - Fixes an issue where the site menu would always display in element selector modals, regardless of whether the "Show site menu" option was actually checked or not. diff --git a/composer.json b/composer.json index b537d28..158829f 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "vaersaagod/linkmate", "description": "Let's hook you up, mate!", "type": "craft-plugin", - "version": "2.2.1", + "version": "2.2.2", "keywords": [ "craft", "cms", diff --git a/src/LinkMate.php b/src/LinkMate.php index f809298..566adfe 100644 --- a/src/LinkMate.php +++ b/src/LinkMate.php @@ -101,15 +101,15 @@ private function createDefaultLinkTypes(): array ]), 'category' => new ElementLinkType([ 'displayGroup' => 'Craft CMS', - 'elementType' => Category::class + 'elementType' => Category::class, ]), 'entry' => new ElementLinkType([ 'displayGroup' => 'Craft CMS', - 'elementType' => Entry::class + 'elementType' => Entry::class, ]), 'user' => new ElementLinkType([ 'displayGroup' => 'Craft CMS', - 'elementType' => User::class + 'elementType' => User::class, ]), 'site' => new SiteLinkType([ 'displayGroup' => 'Craft CMS', diff --git a/src/models/ElementLinkType.php b/src/models/ElementLinkType.php index 33f3383..6ca6fde 100644 --- a/src/models/ElementLinkType.php +++ b/src/models/ElementLinkType.php @@ -6,11 +6,14 @@ use craft\base\ElementInterface; use craft\errors\SiteNotFoundException; use craft\helpers\Html; + use Exception; use Throwable; + use vaersaagod\linkmate\fields\LinkField; use vaersaagod\linkmate\utilities\ElementSourceValidator; use vaersaagod\linkmate\utilities\Url; + use yii\base\Model; /** @@ -24,25 +27,12 @@ */ class ElementLinkType extends Model implements LinkTypeInterface { - public ElementInterface|string $elementType; - public string $displayGroup = 'Common'; - /** - * ElementLinkType constructor. - * - * @param string|array $elementType - * @param array $options - */ - public function __construct($elementType, array $options = []) - { - if (is_array($elementType)) { - $options = $elementType; - } else { - $options['elementType'] = $elementType; - } - - parent::__construct($options); - } + /** @var string The fully qualified element class path, e.g. craft\\elements\\Entry */ + public string $elementType; + + /** @var string */ + public string $displayGroup = 'Common'; /** * @return array @@ -61,8 +51,7 @@ public function getDefaultSettings(): array */ public function getDisplayName(): string { - $elementType = $this->elementType; - return $elementType::displayName(); + return $this->elementType::displayName(); } /** @@ -70,8 +59,7 @@ public function getDisplayName(): string */ public function getPluralDisplayName(): string { - $elementType = $this->elementType; - return $elementType::pluralDisplayName(); + return $this->elementType::pluralDisplayName(); } /** diff --git a/src/utilities/ElementSourceValidator.php b/src/utilities/ElementSourceValidator.php index ad3fd57..3452b5c 100644 --- a/src/utilities/ElementSourceValidator.php +++ b/src/utilities/ElementSourceValidator.php @@ -2,9 +2,9 @@ namespace vaersaagod\linkmate\utilities; -use craft\base\ElementInterface; use Exception; use Throwable; + use yii\helpers\ArrayHelper; /** @@ -26,15 +26,15 @@ class ElementSourceValidator /** * ElementSourceValidator constructor. * - * @param ElementInterface $elementType + * @param string $elementType The fully qualified element class path, e.g. craft\\elements\\Entry * * @throws Exception */ - public function __construct(ElementInterface $elementType) + public function __construct(string $elementType) { $idPath = self::getElementIdPath($elementType); if (is_null($idPath)) { - throw new Exception('Unsupported element type: '.(string)$elementType); + throw new Exception('Unsupported element type: ' . (string)$elementType); } $availableSources = []; @@ -112,12 +112,12 @@ private function validateSource(string $originalSource): ?string } /** - * @param ElementInterface $elementType - * @param array $sources + * @param string $elementType The fully qualified element class path, e.g. craft\\elements\\Entry + * @param array $sources * * @return array */ - public static function apply(ElementInterface $elementType, array $sources): array + public static function apply(string $elementType, array $sources): array { try { if (!array_key_exists($elementType, self::$validators)) { @@ -126,17 +126,18 @@ public static function apply(ElementInterface $elementType, array $sources): arr return self::$validators[(string)$elementType]->validate($sources); } catch (Throwable) { + } return $sources; } /** - * @param ElementInterface $elementType + * @param string $elementType The fully qualified element class path, e.g. craft\\elements\\Entry * * @return array|null */ - public static function getElementIdPath(ElementInterface $elementType): ?array + public static function getElementIdPath(string $elementType): ?array { return match ($elementType) { 'craft\\elements\\Asset' => ['criteria', 'folderId'],