Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add behaviour for Categories Craft 4 #95

Closed
jlachancekffein opened this issue Jul 5, 2024 · 3 comments
Closed

Add behaviour for Categories Craft 4 #95

jlachancekffein opened this issue Jul 5, 2024 · 3 comments
Assignees

Comments

@jlachancekffein
Copy link

The version 4.0.x does not work for categories because the behaviors are not registered.

Here is the solution:

private function _registerElementBehaviors(): void
    {
        Event::on(Entry::class, Entry::EVENT_DEFINE_BEHAVIORS, function (DefineBehaviorsEvent $event) {
            $event->behaviors[$this->id] = ElementSeoBehavior::class;
        });

        /* Category element registration */
        Event::on(Category::class, Category::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;
            });
        }
    }
janhenckens added a commit that referenced this issue Jul 7, 2024
janhenckens added a commit that referenced this issue Jul 7, 2024
@janhenckens
Copy link
Member

Thanks for reporting @jlachancekffein! This was fixed in today's update (version 4.0.10 for Craft 4, 5.0.1 for Craft 5)

@jlachancekffein
Copy link
Author

Sorry, but there is a typo in the 2nd parameter:

Event::on(Category::class, Entry::EVENT_DEFINE_BEHAVIORS, function(DefineBehaviorsEvent $event) {
    $event->behaviors[$this->id] = ElementSeoBehavior::class;
});

Should be Category::EVENT_DEFINE_BEHAVIOR vs Entry::EVENT_DEFINE_BEHAVIORS

@janhenckens
Copy link
Member

That what happens when fixing things quickly... Releases tagged for both again with working code!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants