-
Notifications
You must be signed in to change notification settings - Fork 0
/
Image.php
46 lines (41 loc) · 1.13 KB
/
Image.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
/**
* @link https://craftcms.com/
* @copyright Copyright (c) Pixel & Tonic, Inc.
* @license MIT
*/
namespace craft\wpimport\acfadapters;
use craft\base\FieldInterface;
use craft\fields\Assets;
use craft\wpimport\BaseAcfAdapter;
use craft\wpimport\generators\volumes\Uploads;
use craft\wpimport\importers\Media;
/**
* @author Pixel & Tonic, Inc. <[email protected]>
*/
class Image extends BaseAcfAdapter
{
public static function type(): string
{
return 'image';
}
public function create(array $data): FieldInterface
{
$sourceKey = sprintf('volume:%s', Uploads::get()->uid);
$field = new Assets();
$field->maxRelations = 1;
$field->sources = [$sourceKey];
$field->viewMode = 'large';
$field->defaultUploadLocationSource = $sourceKey;
$field->restrictFiles = true;
$field->allowedKinds = ['image'];
return $field;
}
public function normalizeValue(mixed $value, array $data): mixed
{
return array_map(
fn(int $id) => $this->command->import(Media::SLUG, $id),
(array)$value,
);
}
}