|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @copyright Copyright (c) Flipbox Digital Limited |
|
5
|
|
|
* @license https://flipboxfactory.com/software/organization/license |
|
6
|
|
|
* @link https://www.flipboxfactory.com/software/organization/ |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace flipbox\organization\modules\configuration\controllers; |
|
10
|
|
|
|
|
11
|
|
|
use Craft; |
|
12
|
|
|
use flipbox\organization\models\Settings; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @author Flipbox Factory <[email protected]> |
|
16
|
|
|
* @since 1.0.0 |
|
17
|
|
|
*/ |
|
18
|
|
|
class LayoutController extends AbstractController |
|
19
|
|
|
{ |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @return \yii\web\Response |
|
23
|
|
|
*/ |
|
24
|
|
|
public function actionSave() |
|
25
|
|
|
{ |
|
26
|
|
|
|
|
27
|
|
|
// Admins and Post requests only |
|
28
|
|
|
$this->requireAdmin(); |
|
29
|
|
|
$this->requirePostRequest(); |
|
30
|
|
|
|
|
31
|
|
|
$request = Craft::$app->getRequest(); |
|
32
|
|
|
$session = Craft::$app->getSession(); |
|
33
|
|
|
|
|
34
|
|
|
/** @var Settings $model */ |
|
35
|
|
|
$model = $this->module->module->getSettings(); |
|
36
|
|
|
|
|
37
|
|
|
// Handle each site's url/template settings |
|
38
|
|
|
foreach (Craft::$app->getSites()->getAllSites() as $site) { |
|
39
|
|
|
$namespace = 'sites.' . $site->handle; |
|
40
|
|
|
|
|
41
|
|
|
$siteSettings = $model->getSite($site->id); |
|
42
|
|
|
$siteSettings->hasUrls = !empty($postedSettings['uriFormat']); |
|
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
// Group the field layout |
|
45
|
|
|
$siteSettings->setFieldLayout( |
|
46
|
|
|
Craft::$app->getFields()->assembleLayoutFromPost($namespace) |
|
47
|
|
|
); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
// Save settings |
|
51
|
|
|
if (!$this->module->getLayout()->save($model)) { |
|
52
|
|
|
// Ajax request |
|
53
|
|
|
if (!$request->getAcceptsJson()) { |
|
54
|
|
|
// Fail message |
|
55
|
|
|
$message = Craft::t('organization', 'Settings NOT saved successfully.'); |
|
56
|
|
|
|
|
57
|
|
|
// Flash fail message |
|
58
|
|
|
$session->setError($message); |
|
59
|
|
|
|
|
60
|
|
|
// Send the element back to the template |
|
61
|
|
|
Craft::$app->getUrlManager()->setRouteParams([ |
|
62
|
|
|
'settings' => $model |
|
63
|
|
|
]); |
|
64
|
|
|
|
|
65
|
|
|
// Redirect |
|
66
|
|
|
return $this->redirectToPostedUrl($model); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
return $this->asJson([ |
|
70
|
|
|
'success' => false, |
|
71
|
|
|
'errors' => $model->getErrors(), |
|
72
|
|
|
]); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
// Ajax request |
|
76
|
|
|
if (!$request->getAcceptsJson()) { |
|
77
|
|
|
// Success message |
|
78
|
|
|
$message = Craft::t('organization', 'Settings saved successfully.'); |
|
79
|
|
|
|
|
80
|
|
|
// Flash success message |
|
81
|
|
|
$session->setNotice($message); |
|
82
|
|
|
|
|
83
|
|
|
return $this->redirectToPostedUrl($model); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
return $this->asJson($model); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
This check looks for calls to
isset(...)orempty()on variables that are yet undefined. These calls will always produce the same result and can be removed.This is most likely caused by the renaming of a variable or the removal of a function/method parameter.