/** * @param array|BaseModel $values */ public function setSettings($values) { if (!$values) { $values = array(); } if (is_array($values)) { // Merge in any values that are stored in craft/config/contactform.php foreach ($this->getSettings() as $key => $value) { $configValue = craft()->config->get($key, 'contactform'); if ($configValue !== null) { $values[$key] = $configValue; } } } parent::setSettings($values); }
/** * Saves a plugin's settings. * * @param BasePlugin $plugin The plugin. * @param array $settings The plugin’s new settings. * * @return bool Whether the plugin’s settings were saved successfully. */ public function savePluginSettings(BasePlugin $plugin, $settings) { // Give the plugin a chance to prep the settings from post $preppedSettings = $plugin->prepSettings($settings); // Set the prepped settings on the plugin $plugin->setSettings($preppedSettings); // Validate them, now that it's a model if ($plugin->getSettings()->validate()) { // JSON-encode them and save the plugin row $settings = JsonHelper::encode($plugin->getSettings()->getAttributes()); $affectedRows = craft()->db->createCommand()->update('plugins', array('settings' => $settings), array('class' => $plugin->getClassHandle())); return (bool) $affectedRows; } }