1 | <?php |
||
19 | class AssetSources extends Base |
||
20 | { |
||
21 | /** |
||
22 | * @return AssetSourcesService |
||
23 | */ |
||
24 | 4 | private function getAssetSourcesService() |
|
28 | |||
29 | /** |
||
30 | * Export all asset sources. |
||
31 | * |
||
32 | * @param AssetSourceModel[] $assetSources |
||
33 | * |
||
34 | * @return array |
||
35 | */ |
||
36 | 3 | public function export(array $assetSources = []) |
|
48 | |||
49 | /** |
||
50 | * @param AssetSourceModel $assetSource |
||
51 | * |
||
52 | * @return array |
||
53 | */ |
||
54 | 2 | private function getAssetSourceDefinition(AssetSourceModel $assetSource) |
|
64 | |||
65 | /** |
||
66 | * Import asset source definitions. |
||
67 | * |
||
68 | * @param array $assetSourceDefinitions |
||
69 | * @param bool $force |
||
70 | * |
||
71 | * @return Result |
||
72 | */ |
||
73 | 4 | public function import(array $assetSourceDefinitions, $force = false) |
|
104 | |||
105 | /** |
||
106 | * Populate asset source. |
||
107 | * |
||
108 | * @param AssetSourceModel $assetSource |
||
109 | * @param array $assetSourceDefinition |
||
110 | * @param string $assetSourceHandle |
||
111 | * |
||
112 | * @return AssetSourceModel |
||
113 | */ |
||
114 | 2 | private function populateAssetSource(AssetSourceModel $assetSource, array $assetSourceDefinition, $assetSourceHandle) |
|
115 | { |
||
116 | $defaultAssetSourceSettings = array( |
||
117 | 2 | 'publicURLs' => true, |
|
118 | 2 | ); |
|
119 | |||
120 | 2 | $assetSource->setAttributes([ |
|
121 | 2 | 'handle' => $assetSourceHandle, |
|
122 | 2 | 'type' => $assetSourceDefinition['type'], |
|
123 | 'name' => $assetSourceDefinition['name'], |
||
124 | 'sortOrder' => $assetSourceDefinition['sortOrder'], |
||
125 | 'settings' => array_merge($defaultAssetSourceSettings, $assetSourceDefinition['settings']), |
||
126 | ]); |
||
127 | |||
128 | if (array_key_exists('fieldLayout', $assetSourceDefinition)) { |
||
129 | $fieldLayout = Craft::app()->schematic_fields->getFieldLayout($assetSourceDefinition['fieldLayout']); |
||
130 | $assetSource->setFieldLayout($fieldLayout); |
||
131 | } |
||
132 | |||
133 | return $assetSource; |
||
134 | } |
||
135 | |||
136 | /** |
||
137 | * Reset craft fields service cache using reflection. |
||
138 | */ |
||
139 | 4 | private function resetCraftAssetSourcesServiceCache() |
|
154 | } |
||
155 |