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 defineBehaviors() to base Model #10691

Merged
merged 1 commit into from
Mar 7, 2022
Merged

Conversation

bencroker
Copy link
Contributor

This PR adds a defineBehaviors() to the base Model class, making it easier for models to attach behaviors without having to call the parent method, similar to defineRules(). It also uses the behaviors attribute of the DefineBehaviorsEvent event so that plugins can modify behaviors already defined.

Usage before:

    public function behaviors(): array
    {
        $behaviors = parent::behaviors();
        $behaviors['parser'] = [
            'class' => EnvAttributeParserBehavior::class,
            'attributes' => ['apiKey'],
        ];

        return $behaviors;
    }

Usage after:

    public function defineBehaviors(): array
    {
        return [
            'parser' => [
                'class' => EnvAttributeParserBehavior::class,
                'attributes' => ['apiKey'],
            ],
        ];
    }

@bencroker bencroker changed the title Added defineBehaviors() to base Model Add defineBehaviors() to base Model Mar 5, 2022
@brandonkelly brandonkelly merged commit 6e3654d into craftcms:4.0 Mar 7, 2022
@brandonkelly
Copy link
Member

Like it, thanks!

brandonkelly added a commit that referenced this pull request Mar 7, 2022
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

Successfully merging this pull request may close these issues.

2 participants