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

Missing parent::rules() for ElementTypes #102

Open
jerome2710 opened this issue Jul 6, 2020 · 0 comments
Open

Missing parent::rules() for ElementTypes #102

jerome2710 opened this issue Jul 6, 2020 · 0 comments
Labels

Comments

@jerome2710
Copy link

I was having a really hard time figuring out why my custom ElementType would not save. Figured out the generated element overrides the public function rules() of the \yii\base\Model::validate, but does not call the parent::rules().

Exception thrown was:
[error][yii\base\InvalidArgumentException] yii\base\InvalidArgumentException: Unknown scenario: essentials in [redacted]/vendor/yiisoft/yii2/base/Model.php:357

Generated \modules\somemodule\elements\CustomElement::rules was:

public function rules()
{
    return [
        ['someAttribute', 'string'],
        ['someAttribute', 'default', 'value' => 'Some Default'],
    ];
}

should be:

public function rules()
{
    $rules = parent::rules();

    $rules[] = ['someAttribute', 'string'];
    $rules[] = ['someAttribute', 'default', 'value' => 'Some Default'];

    return $rules;
}
@jerome2710 jerome2710 added the bug label Jul 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant