Skip to content

Commit

Permalink
Merge branch 'develop' into develop-v5
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
#	composer.json
#	src/SeoFields.php
  • Loading branch information
janhenckens committed Feb 27, 2024
2 parents daec68f + caf3fdb commit 37c098d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
21 changes: 17 additions & 4 deletions src/SeoFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
* @property EntryQuery $owner
*/
class EntrySeoBehavior extends Behavior
class ElementSeoBehavior extends Behavior
{
public bool $shouldRenderSchema = true;

Expand Down

0 comments on commit 37c098d

Please sign in to comment.