Include event information in migrated events
This commit is contained in:
parent
599dff7720
commit
f17eb0c154
|
@ -42,6 +42,10 @@ source:
|
||||||
selector: speakerdeck
|
selector: speakerdeck
|
||||||
label: Speakerdeck
|
label: Speakerdeck
|
||||||
|
|
||||||
|
- name: events
|
||||||
|
selector: events
|
||||||
|
label: Events
|
||||||
|
|
||||||
process:
|
process:
|
||||||
body/0/format:
|
body/0/format:
|
||||||
plugin: default_value
|
plugin: default_value
|
||||||
|
@ -72,7 +76,7 @@ process:
|
||||||
default_value: 1
|
default_value: 1
|
||||||
|
|
||||||
destination:
|
destination:
|
||||||
plugin: 'entity:node'
|
plugin: opd_talk
|
||||||
|
|
||||||
migration_dependencies:
|
migration_dependencies:
|
||||||
required: { }
|
required: { }
|
||||||
|
|
|
@ -0,0 +1,67 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Drupal\custom\Plugin\migrate\destination;
|
||||||
|
|
||||||
|
use Drupal\Core\Datetime\DrupalDateTime;
|
||||||
|
use Drupal\Core\Entity\EntityInterface;
|
||||||
|
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface;
|
||||||
|
use Drupal\migrate\Annotation\MigrateDestination;
|
||||||
|
use Drupal\migrate\Plugin\migrate\destination\EntityContentBase;
|
||||||
|
use Drupal\migrate\Row;
|
||||||
|
use Drupal\paragraphs\Entity\Paragraph;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @MigrateDestination(
|
||||||
|
* id="opd_talk"
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
class OpdTalk extends EntityContentBase {
|
||||||
|
|
||||||
|
protected static function getEntityTypeId($plugin_id) {
|
||||||
|
return 'node';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function import(Row $row, array $old_destination_id_values = []) {
|
||||||
|
$data = $row->getDestination();
|
||||||
|
|
||||||
|
if ($nodes = $this->storage->loadByProperties(['title' => $data['title']])) {
|
||||||
|
$node = current($nodes);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$node = $this->storage->create($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
$eventData = $row->getSourceProperty('events');
|
||||||
|
$this->createEventParagraphs($node, $eventData);
|
||||||
|
|
||||||
|
$node->save();
|
||||||
|
|
||||||
|
return [$node->id()];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createEventParagraphs(EntityInterface $node, array $eventData): void {
|
||||||
|
Collection::make($eventData)->map(function (array $event): array {
|
||||||
|
$paragraph = Paragraph::create([
|
||||||
|
'field_date' => DrupalDateTime::createFromTimestamp($event['date'])
|
||||||
|
->format(DateTimeItemInterface::DATE_STORAGE_FORMAT),
|
||||||
|
'field_link' => $event['url'],
|
||||||
|
'field_location' => $event['location'],
|
||||||
|
'field_name' => $event['name'],
|
||||||
|
'field_remote' => $event['remote'] == 'true' ? 1 : 0,
|
||||||
|
'type' => 'event',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$paragraph->save();
|
||||||
|
|
||||||
|
return [
|
||||||
|
'target_id' => $paragraph->id(),
|
||||||
|
'target_revision_id' => $paragraph->getRevisionId(),
|
||||||
|
];
|
||||||
|
})->pipe(function (Collection $events) use ($node) {
|
||||||
|
$node->set('field_events', $events->toArray());
|
||||||
|
$node->save();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue