Add talk videos in the migration
This commit is contained in:
parent
0bec0f5c7b
commit
ee7b24d778
|
@ -46,6 +46,10 @@ source:
|
||||||
selector: events
|
selector: events
|
||||||
label: Events
|
label: Events
|
||||||
|
|
||||||
|
- name: video
|
||||||
|
selector: video
|
||||||
|
label: Video
|
||||||
|
|
||||||
process:
|
process:
|
||||||
body/0/format:
|
body/0/format:
|
||||||
plugin: default_value
|
plugin: default_value
|
||||||
|
|
|
@ -7,6 +7,7 @@ namespace Drupal\custom\Plugin\migrate\destination;
|
||||||
use Drupal\Core\Datetime\DrupalDateTime;
|
use Drupal\Core\Datetime\DrupalDateTime;
|
||||||
use Drupal\Core\Entity\EntityInterface;
|
use Drupal\Core\Entity\EntityInterface;
|
||||||
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface;
|
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface;
|
||||||
|
use Drupal\media\Entity\Media;
|
||||||
use Drupal\migrate\Annotation\MigrateDestination;
|
use Drupal\migrate\Annotation\MigrateDestination;
|
||||||
use Drupal\migrate\Plugin\migrate\destination\EntityContentBase;
|
use Drupal\migrate\Plugin\migrate\destination\EntityContentBase;
|
||||||
use Drupal\migrate\Row;
|
use Drupal\migrate\Row;
|
||||||
|
@ -36,15 +37,17 @@ final class OpdTalk extends EntityContentBase {
|
||||||
$node = $this->storage->create($data);
|
$node = $this->storage->create($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
$eventData = $row->getSourceProperty('events');
|
$this->createEventParagraphs($row, $node);
|
||||||
$this->createEventParagraphs($node, $eventData);
|
$this->createVideoMedia($row, $node);
|
||||||
|
|
||||||
$node->save();
|
$node->save();
|
||||||
|
|
||||||
return [$node->id()];
|
return [$node->id()];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createEventParagraphs(EntityInterface $node, array $eventData): void {
|
private function createEventParagraphs(Row $row, EntityInterface $node): void {
|
||||||
|
$eventData = $row->getSourceProperty('events');
|
||||||
|
|
||||||
Collection::make($eventData)->map(function (array $event): array {
|
Collection::make($eventData)->map(function (array $event): array {
|
||||||
$paragraph = Paragraph::create([
|
$paragraph = Paragraph::create([
|
||||||
'field_date' => DrupalDateTime::createFromTimestamp($event['date'])
|
'field_date' => DrupalDateTime::createFromTimestamp($event['date'])
|
||||||
|
@ -64,8 +67,33 @@ final class OpdTalk extends EntityContentBase {
|
||||||
];
|
];
|
||||||
})->pipe(function (Collection $events) use ($node) {
|
})->pipe(function (Collection $events) use ($node) {
|
||||||
$node->set('field_events', $events->toArray());
|
$node->set('field_events', $events->toArray());
|
||||||
$node->save();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function createVideoMedia(Row $row, EntityInterface $node) {
|
||||||
|
$video = $row->getSourceProperty('video');
|
||||||
|
|
||||||
|
if (!empty($video['type']) && !empty($video['id'])) {
|
||||||
|
$video = Media::create([
|
||||||
|
'bundle' => 'video',
|
||||||
|
'field_media_oembed_video' => [
|
||||||
|
'value' => $this->getVideoUrlFromId($video),
|
||||||
|
],
|
||||||
|
'langcode' => \Drupal::languageManager()->getDefaultLanguage()->getId(),
|
||||||
|
'uid' => 1,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$node->set('field_video', tap($video)->save());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getVideoUrlFromId(array $video): string {
|
||||||
|
$urls = new Collection([
|
||||||
|
'vimeo' => 'https://vimeo.com/',
|
||||||
|
'youtube' => 'https://www.youtube.com/watch?v=',
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $urls->get($video['type']) . $video['id'];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue