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\organizations\actions\organizations; |
10
|
|
|
|
11
|
|
|
use Craft; |
12
|
|
|
use flipbox\organizations\cp\actions\general\traits\SiteSettingAttributesTrait; |
13
|
|
|
use flipbox\organizations\Organizations; |
14
|
|
|
use flipbox\organizations\records\OrganizationType; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @author Flipbox Factory <[email protected]> |
18
|
|
|
* @since 1.0.0 |
19
|
|
|
*/ |
20
|
|
|
trait PopulateOrganizationTypeTrait |
21
|
|
|
{ |
22
|
|
|
use SiteSettingAttributesTrait; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* These are the default body params that we're accepting. You can lock down specific Client attributes this way. |
26
|
|
|
* |
27
|
|
|
* @return array |
28
|
|
|
*/ |
29
|
|
|
protected function validBodyParams(): array |
30
|
|
|
{ |
31
|
|
|
return [ |
32
|
|
|
'name', |
33
|
|
|
'handle' |
34
|
|
|
]; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param OrganizationType $model |
39
|
|
|
* @return OrganizationType |
40
|
|
|
*/ |
41
|
|
|
private function populateSiteLayout(OrganizationType $model): OrganizationType |
42
|
|
|
{ |
43
|
|
|
$layoutOverride = (bool)Craft::$app->getRequest()->getBodyParam('fieldLayoutOverride'); |
44
|
|
|
|
45
|
|
|
if ($layoutOverride) { |
46
|
|
|
$fieldLayout = Craft::$app->getFields()->assembleLayoutFromPost(); |
47
|
|
|
} else { |
48
|
|
|
$fieldLayout = Organizations::getInstance()->getSettings()->getFieldLayout(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$model->setFieldLayout($fieldLayout); |
52
|
|
|
|
53
|
|
|
return $model; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param OrganizationType $model |
58
|
|
|
* @return OrganizationType |
59
|
|
|
*/ |
60
|
|
|
private function populateSiteSettings(OrganizationType $model): OrganizationType |
61
|
|
|
{ |
62
|
|
|
if (null !== ($sites = $this->sitesSettingsFromBody())) { |
63
|
|
|
$enabledSites = []; |
64
|
|
|
|
65
|
|
|
foreach ($sites as $siteId => $siteConfig) { |
66
|
|
|
if (!($siteConfig['enabled'] ?? false)) { |
67
|
|
|
continue; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$siteConfig['siteId'] = $siteId; |
71
|
|
|
$enabledSites[$siteId] = $siteConfig; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
$model->setSiteSettings($enabledSites); |
75
|
|
|
} |
76
|
|
|
return $model; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|