Skip to content

Missing parent::rules() for ElementTypes #102

@jerome2710

Description

@jerome2710

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;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions