diff --git a/src/Plugin.php b/src/Plugin.php index d33133c..8f24df1 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -18,6 +18,7 @@ use craft\events\DefineConsoleActionsEvent; use craft\events\RegisterComponentTypesEvent; use craft\events\RegisterUrlRulesEvent; +use craft\fields\Link; use craft\helpers\UrlHelper; use craft\services\Elements; use craft\services\Fields; @@ -25,6 +26,7 @@ use craft\shopify\elements\Product; use craft\shopify\fields\Products as ProductsField; use craft\shopify\handlers\Product as ProductHandler; +use craft\shopify\linktypes\Product as ProductLinkType; use craft\shopify\models\Settings; use craft\shopify\services\Api; use craft\shopify\services\Products; @@ -113,6 +115,7 @@ public function init() $this->_registerElementTypes(); $this->_registerUtilityTypes(); $this->_registerFieldTypes(); + $this->_registerLinkTypes(); $this->_registerVariables(); $this->_registerResaveCommands(); @@ -214,6 +217,22 @@ private function _registerFieldTypes(): void }); } + /** + * Register Link types + * + * @since 5.2.0 + */ + private function _registerLinkTypes(): void + { + if (!class_exists(Link::class)) { + return; + } + + Event::on(Link::class, Link::EVENT_REGISTER_LINK_TYPES, function(RegisterComponentTypesEvent $event) { + $event->types[] = ProductLinkType::class; + }); + } + /** * Register Shopify twig variables to the main craft variable * diff --git a/src/linktypes/Product.php b/src/linktypes/Product.php new file mode 100644 index 0000000..a8825c3 --- /dev/null +++ b/src/linktypes/Product.php @@ -0,0 +1,32 @@ + + * @since 5.2.0 + */ +class Product extends BaseElementLinkType +{ + protected static function elementType(): string + { + return ProductElement::class; + } + + public static function displayName(): string + { + return ProductElement::lowerDisplayName(); + } + +}