|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace NerdsAndCompany\Schematic\Services; |
|
4
|
|
|
|
|
5
|
|
|
use Craft; |
|
6
|
|
|
use craft\elements\User; |
|
7
|
|
|
use yii\base\Component as BaseComponent; |
|
8
|
|
|
use NerdsAndCompany\Schematic\Behaviors\FieldLayoutBehavior; |
|
9
|
|
|
use NerdsAndCompany\Schematic\Interfaces\MappingInterface; |
|
10
|
|
|
use NerdsAndCompany\Schematic\Schematic; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Schematic Users Service. |
|
14
|
|
|
* |
|
15
|
|
|
* Sync Craft Setups. |
|
16
|
|
|
* |
|
17
|
|
|
* @author Nerds & Company |
|
18
|
|
|
* @copyright Copyright (c) 2015-2018, Nerds & Company |
|
19
|
|
|
* @license MIT |
|
20
|
|
|
* |
|
21
|
|
|
* @see http://www.nerds.company |
|
22
|
|
|
*/ |
|
23
|
|
|
class Users extends BaseComponent implements MappingInterface |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* Load fieldlayout behavior |
|
27
|
|
|
* |
|
28
|
|
|
* @return array |
|
29
|
1 |
|
*/ |
|
30
|
|
|
public function behaviors() |
|
31
|
1 |
|
{ |
|
32
|
|
|
return [ |
|
33
|
1 |
|
FieldLayoutBehavior::className(), |
|
|
|
|
|
|
34
|
|
|
]; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
//============================================================================================================== |
|
38
|
|
|
//================================================ EXPORT ==================================================== |
|
39
|
|
|
//============================================================================================================== |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Export user settings |
|
43
|
1 |
|
* |
|
44
|
|
|
* @return array |
|
45
|
|
|
*/ |
|
46
|
1 |
|
public function export() |
|
47
|
1 |
|
{ |
|
48
|
|
|
$settings = Craft::$app->getSystemSettings()->getSettings('users'); |
|
49
|
|
|
$fieldLayout = Craft::$app->getFields()->getLayoutByType(User::class); |
|
50
|
|
|
return [ |
|
51
|
|
|
'settings' => $settings, |
|
52
|
|
|
'fieldLayout' => $this->getFieldLayoutDefinition($fieldLayout), |
|
|
|
|
|
|
53
|
|
|
]; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
//============================================================================================================== |
|
57
|
|
|
//================================================ IMPORT ==================================================== |
|
58
|
3 |
|
//============================================================================================================== |
|
59
|
|
|
|
|
60
|
3 |
|
/** |
|
61
|
|
|
* Attempt to import user settings. |
|
62
|
|
|
* |
|
63
|
3 |
|
* @param array $userSettings |
|
64
|
|
|
*/ |
|
65
|
3 |
|
public function import(array $userSettings) |
|
66
|
1 |
|
{ |
|
67
|
1 |
|
// always delete existing fieldlayout first |
|
68
|
2 |
|
Craft::$app->fields->deleteLayoutsByType(User::class); |
|
69
|
|
|
|
|
70
|
|
|
if (isset($userSettings['fieldLayout'])) { |
|
71
|
3 |
|
$fieldLayoutDefinition = (array) $userSettings['fieldLayout']; |
|
72
|
3 |
|
} else { |
|
73
|
|
|
$fieldLayoutDefinition = []; |
|
74
|
3 |
|
} |
|
75
|
|
|
|
|
76
|
1 |
|
$fieldLayout = Craft::$app->schematic_fields->getFieldLayout($fieldLayoutDefinition); |
|
77
|
1 |
|
$fieldLayout->type = User::class; |
|
78
|
|
|
|
|
79
|
3 |
|
if (!Craft::$app->fields->saveLayout($fieldLayout)) { // Save fieldlayout via craft |
|
80
|
|
|
$this->addErrors($fieldLayout->getAllErrors()); |
|
|
|
|
|
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.