1 | <?php |
||
2 | /** |
||
3 | * Socializer plugin for Craft CMS 3.x |
||
4 | * |
||
5 | * @link https://enupal.com/ |
||
6 | * @copyright Copyright (c) 2019 Enupal LLC |
||
7 | */ |
||
8 | |||
9 | namespace enupal\socializer\controllers; |
||
10 | |||
11 | use Craft; |
||
12 | use craft\web\Controller as BaseController; |
||
13 | use enupal\socializer\Socializer; |
||
14 | |||
15 | class SettingsController extends BaseController |
||
16 | { |
||
17 | /** |
||
18 | * Save Plugin Settings |
||
19 | * |
||
20 | * @return \yii\web\Response |
||
21 | * @throws \craft\errors\MissingComponentException |
||
22 | * @throws \yii\web\BadRequestHttpException |
||
23 | */ |
||
24 | public function actionSaveSettings() |
||
25 | { |
||
26 | $this->requirePostRequest(); |
||
27 | $settings = Craft::$app->getRequest()->getBodyParam('settings'); |
||
28 | $message = Craft::t('enupal-socializer','Settings saved.'); |
||
29 | |||
30 | $plugin = Socializer::$app->settings->getPlugin(); |
||
31 | $settingsModel = $plugin->getSettings(); |
||
32 | |||
33 | $settingsModel->setAttributes($settings, false); |
||
34 | |||
35 | if (!Socializer::$app->settings->saveSettings($settingsModel)) { |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
36 | |||
37 | Craft::$app->getSession()->setError(Craft::t('enupal-socializer','Couldn’t save settings.')); |
||
38 | |||
39 | // Send the settings back to the template |
||
40 | Craft::$app->getUrlManager()->setRouteParams([ |
||
41 | 'settings' => $settingsModel |
||
42 | ]); |
||
43 | |||
44 | return null; |
||
45 | } |
||
46 | |||
47 | Craft::$app->getSession()->setNotice($message); |
||
48 | |||
49 | return $this->redirectToPostedUrl(); |
||
50 | } |
||
51 | } |
||
52 |