Skip to content

Commit

Permalink
Commerce support for #92
Browse files Browse the repository at this point in the history
  • Loading branch information
janhenckens committed Feb 27, 2024
1 parent 6d8f78e commit cfae7fc
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## 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.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "studioespresso/craft-seo-fields",
"description": "Fields for your SEO & OG meta data",
"type": "craft-plugin",
"version": "4.0.5",
"version": "4.0.6",
"keywords": [
"craft",
"cms",
Expand Down
22 changes: 17 additions & 5 deletions src/SeoFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Craft;
use craft\base\Plugin;
use craft\commerce\elements\Product;
use craft\elements\Entry;
use craft\events\DefineBehaviorsEvent;
use craft\events\ElementEvent;
Expand All @@ -34,7 +35,7 @@
use craft\utilities\ClearCaches;
use craft\web\ErrorHandler;
use craft\web\UrlManager;
use studioespresso\seofields\behaviors\EntrySeoBehavior;
use studioespresso\seofields\behaviors\ElementSeoBehavior;
use studioespresso\seofields\events\RegisterSeoElementEvent;
use studioespresso\seofields\extensions\SeoFieldsExtension;
use studioespresso\seofields\fields\SeoField;
Expand Down Expand Up @@ -121,10 +122,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
Expand Down Expand Up @@ -467,4 +465,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;
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*
* @property EntryQuery $owner
*/
class EntrySeoBehavior extends Behavior
class ElementSeoBehavior extends Behavior
{
public bool $shouldRenderSchema = true;

Expand Down

0 comments on commit cfae7fc

Please sign in to comment.