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;
}
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 theparent::rules().Exception thrown was:
[error][yii\base\InvalidArgumentException] yii\base\InvalidArgumentException: Unknown scenario: essentials in [redacted]/vendor/yiisoft/yii2/base/Model.php:357Generated
\modules\somemodule\elements\CustomElement::ruleswas:should be: