1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NerdsAndCompany\Schematic\Converters\Fields; |
4
|
|
|
|
5
|
|
|
use Craft; |
6
|
|
|
use craft\base\Model; |
7
|
|
|
use NerdsAndCompany\Schematic\Schematic; |
8
|
|
|
use NerdsAndCompany\Schematic\Converters\Base\Field; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Schematic Asset Converter. |
12
|
|
|
* |
13
|
|
|
* Sync Craft Setups. |
14
|
|
|
* |
15
|
|
|
* @author Nerds & Company |
16
|
|
|
* @copyright Copyright (c) 2015-2019, Nerds & Company |
17
|
|
|
* @license MIT |
18
|
|
|
* |
19
|
|
|
* @see http://www.nerds.company |
20
|
|
|
*/ |
21
|
|
|
class Assets extends Field |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* {@inheritdoc} |
25
|
|
|
*/ |
26
|
1 |
|
public function getRecordDefinition(Model $record): array |
27
|
|
|
{ |
28
|
1 |
|
$definition = parent::getRecordDefinition($record); |
29
|
|
|
|
30
|
1 |
|
unset($definition['attributes']['targetSiteId']); |
31
|
|
|
|
32
|
1 |
|
if (isset($definition['attributes']['defaultUploadLocationSource'])) { |
33
|
1 |
|
$definition['attributes']['defaultUploadLocationSource'] = $this->getSource( |
34
|
1 |
|
$definition['class'], |
35
|
1 |
|
$definition['attributes']['defaultUploadLocationSource'], |
36
|
1 |
|
'id', |
37
|
1 |
|
'handle' |
38
|
|
|
); |
39
|
|
|
} |
40
|
|
|
|
41
|
1 |
|
if (isset($definition['attributes']['singleUploadLocationSource'])) { |
42
|
1 |
|
$definition['attributes']['singleUploadLocationSource'] = $this->getSource( |
43
|
1 |
|
$definition['class'], |
44
|
1 |
|
$definition['attributes']['singleUploadLocationSource'], |
45
|
1 |
|
'id', |
46
|
1 |
|
'handle' |
47
|
|
|
); |
48
|
|
|
} |
49
|
|
|
|
50
|
1 |
|
return $definition; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* {@inheritdoc} |
55
|
|
|
*/ |
56
|
1 |
|
public function setRecordAttributes(Model &$record, array $definition, array $defaultAttributes) |
57
|
|
|
{ |
58
|
1 |
|
if (isset($definition['attributes']['defaultUploadLocationSource'])) { |
59
|
1 |
|
$definition['attributes']['defaultUploadLocationSource'] = $this->getSource( |
60
|
1 |
|
$definition['class'], |
61
|
1 |
|
$definition['attributes']['defaultUploadLocationSource'], |
62
|
1 |
|
'handle', |
63
|
1 |
|
'id' |
64
|
|
|
); |
65
|
|
|
} |
66
|
|
|
|
67
|
1 |
|
if (isset($definition['attributes']['singleUploadLocationSource'])) { |
68
|
1 |
|
$definition['attributes']['singleUploadLocationSource'] = $this->getSource( |
69
|
1 |
|
$definition['class'], |
70
|
1 |
|
$definition['attributes']['singleUploadLocationSource'], |
71
|
1 |
|
'handle', |
72
|
1 |
|
'id' |
73
|
|
|
); |
74
|
|
|
} |
75
|
|
|
|
76
|
1 |
|
parent::setRecordAttributes($record, $definition, $defaultAttributes); |
77
|
1 |
|
} |
78
|
|
|
} |
79
|
|
|
|