diff --git a/CHANGELOG.md b/CHANGELOG.md index b21718e..a837e94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,16 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ### Added - Initial Craft 5 support 🚀 + +## 4.0.6 - 2024-02-27 +### Fixed +- Fixed support for Commerce Products ([#92](https://github.com/studioespresso/craft-seo-fields/issues/92)) + + +## 4.0.5 - 2024-02-16 +### Fixed +- Change schema version to fix an issue with migrations from 4.0.0 not being applied correctly. + ## 4.0.4 - 2024-02-05 ### Fixed - Fixed an issue where the "Allow sitename to be hidden" option would not work ([#90](https://github.com/studioespresso/craft-seo-fields/issues/90)) diff --git a/src/SeoFields.php b/src/SeoFields.php index c2782dc..c428bf1 100644 --- a/src/SeoFields.php +++ b/src/SeoFields.php @@ -13,6 +13,7 @@ use Craft; use craft\base\Model; use craft\base\Plugin; +use craft\commerce\elements\Product; use craft\elements\Entry; use craft\events\DefineBehaviorsEvent; use craft\events\ElementEvent; @@ -36,6 +37,7 @@ use craft\web\ErrorHandler; use craft\web\UrlManager; use putyourlightson\sprig\Sprig; +use studioespresso\seofields\behaviors\ElementSeoBehavior; use studioespresso\seofields\behaviors\EntrySeoBehavior; use studioespresso\seofields\events\RegisterSeoElementEvent; use studioespresso\seofields\extensions\SeoFieldsExtension; @@ -126,10 +128,7 @@ public function init() $this->_registerCacheOptions(); $this->_registerCustomElements(); $this->_registerUrlChangeListeners(); - - Event::on(Entry::class, Entry::EVENT_DEFINE_BEHAVIORS, function(DefineBehaviorsEvent $event) { - $event->behaviors[$this->id] = EntrySeoBehavior::class; - }); + $this->_registerElementBehaviors(); } public function getCpNavItem(): ?array @@ -470,4 +469,18 @@ function(RegisterSeoElementEvent $event) use ($elements) { ); } } + + private function _registerElementBehaviors(): void + { + Event::on(Entry::class, Entry::EVENT_DEFINE_BEHAVIORS, function(DefineBehaviorsEvent $event) { + $event->behaviors[$this->id] = ElementSeoBehavior::class; + }); + + if (Craft::$app->getPlugins()->isPluginEnabled('commerce')) { + /** @phpstan-ignore-next-line */ + Event::on(Product::class, Product::EVENT_DEFINE_BEHAVIORS, function(DefineBehaviorsEvent $event) { + $event->behaviors[$this->id] = ElementSeoBehavior::class; + }); + } + } } diff --git a/src/behaviors/EntrySeoBehavior.php b/src/behaviors/ElementSeoBehavior.php similarity index 99% rename from src/behaviors/EntrySeoBehavior.php rename to src/behaviors/ElementSeoBehavior.php index 0e00ae6..8d0742f 100644 --- a/src/behaviors/EntrySeoBehavior.php +++ b/src/behaviors/ElementSeoBehavior.php @@ -12,7 +12,7 @@ * * @property EntryQuery $owner */ -class EntrySeoBehavior extends Behavior +class ElementSeoBehavior extends Behavior { public bool $shouldRenderSchema = true;