As a follow-up to this thread, I would like to know how to create custom validation rules for plugin settings, or at least how to return field errors to the plugin settings view. I currently have:
<?php namespace Craft;
class SamplePlugin extends BasePlugin {
function getName() { ... }
function getVersion() { ... }
function getDeveloper() { ... }
function getDeveloperUrl() { ... }
public function getSettingsHtml()
{
return craft()->templates->render('sample/settings', [
'settings' => $this->getSettings()
]);
}
public function prepSettings($settings)
{
// I'm currently doing my 'custom' validation here. But if
// there's an error, how do I display errors on the settings page?
return $settings;
}
public function rules()
{
// Tried this, but since SamplePlugin isn't a Model, it does nothing.
}
protected function defineSettings()
{
return [
'mySetting' => [
AttributeType::String,
'required' => true,
// Can custom validation rules be set here?
]
];
}
}
$this->settings
is the plugin settings model. That get's me going in the right direction.