-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7263d23
commit 642133d
Showing
3 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
/** | ||
* @link https://craftcms.com/ | ||
* @copyright Copyright (c) Pixel & Tonic, Inc. | ||
* @license MIT | ||
*/ | ||
|
||
namespace craft\wpimport\acfadapters; | ||
|
||
use craft\base\FieldInterface; | ||
use craft\fields\Entries; | ||
use craft\wpimport\BaseAcfAdapter; | ||
use craft\wpimport\importers\PostType; | ||
use yii\console\Exception; | ||
|
||
/** | ||
* @author Pixel & Tonic, Inc. <[email protected]> | ||
*/ | ||
class PostObject extends BaseAcfAdapter | ||
{ | ||
public static function type(): string | ||
{ | ||
return 'post_object'; | ||
} | ||
|
||
public function create(array $data): FieldInterface | ||
{ | ||
$field = new Entries(); | ||
$field->sources = array_map(function(string $type) use ($data) { | ||
$importer = $this->command->importers[$type] ?? null; | ||
if (!$importer instanceof PostType) { | ||
throw new Exception("Unsupported post type in the {$data['label']} field: $type"); | ||
} | ||
return sprintf('section:%s', $importer->section()->uid); | ||
}, $data['post_type']); | ||
$field->maxRelations = 1; | ||
return $field; | ||
} | ||
|
||
public function normalizeValue(mixed $value, array $data): mixed | ||
{ | ||
if (count($data['post_type']) === 1) { | ||
$type = reset($data['post_type']); | ||
$id = $this->command->import($type, $value); | ||
} else { | ||
$id = $this->command->importPost($value); | ||
} | ||
|
||
return [$id]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters