Skip to content

Commit

Permalink
Adds Link field support
Browse files Browse the repository at this point in the history
  • Loading branch information
olivierbon committed Sep 19, 2024
1 parent fd470a9 commit 833956a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
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;
use craft\services\Utilities;
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;
Expand Down Expand Up @@ -113,6 +115,7 @@ public function init()
$this->_registerElementTypes();
$this->_registerUtilityTypes();
$this->_registerFieldTypes();
$this->_registerLinkTypes();
$this->_registerVariables();
$this->_registerResaveCommands();

Expand Down Expand Up @@ -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
*
Expand Down
32 changes: 32 additions & 0 deletions src/linktypes/Product.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* @link https://craftcms.com/
* @copyright Copyright (c) Pixel & Tonic, Inc.
* @license https://craftcms.github.io/license/
*/

namespace craft\shopify\linktypes;

use craft\shopify\elements\Product as ProductElement;
use craft\fields\linktypes\BaseElementLinkType;


/**
* Shopify Product link type.
*
* @author Pixel & Tonic, Inc. <[email protected]>
* @since 5.2.0
*/
class Product extends BaseElementLinkType

Check failure on line 20 in src/linktypes/Product.php

View workflow job for this annotation

GitHub Actions / ci / Code Quality / PHPStan / PHPStan

Class craft\shopify\linktypes\Product extends unknown class craft\fields\linktypes\BaseElementLinkType.
{
protected static function elementType(): string
{
return ProductElement::class;
}

public static function displayName(): string
{
return ProductElement::lowerDisplayName();
}

}

0 comments on commit 833956a

Please sign in to comment.