parent
c25eaf4ee1
commit
a36654cfbb
|
@ -1,82 +0,0 @@
|
||||||
id: post_node
|
|
||||||
|
|
||||||
source:
|
|
||||||
plugin: url
|
|
||||||
data_fetcher_plugin: http
|
|
||||||
data_parser_plugin: json
|
|
||||||
|
|
||||||
urls: https://opdavies.netlify.app/posts.json
|
|
||||||
|
|
||||||
ids:
|
|
||||||
id:
|
|
||||||
type: integer
|
|
||||||
|
|
||||||
item_selector: posts/
|
|
||||||
|
|
||||||
fields:
|
|
||||||
- name: id
|
|
||||||
selector: id
|
|
||||||
label: Node ID
|
|
||||||
|
|
||||||
- name: title
|
|
||||||
selector: title
|
|
||||||
label: Title
|
|
||||||
|
|
||||||
- name: excerpt
|
|
||||||
selector: excerpt
|
|
||||||
label: Excerpt
|
|
||||||
|
|
||||||
- name: created
|
|
||||||
selector: created
|
|
||||||
label: Created
|
|
||||||
|
|
||||||
- name: status
|
|
||||||
selector: status
|
|
||||||
label: Status
|
|
||||||
|
|
||||||
- name: content
|
|
||||||
selector: content
|
|
||||||
label: Content
|
|
||||||
|
|
||||||
- name: path
|
|
||||||
selector: path
|
|
||||||
label: Path
|
|
||||||
|
|
||||||
- name: tags
|
|
||||||
selector: tags
|
|
||||||
label: Tags
|
|
||||||
|
|
||||||
process:
|
|
||||||
body/0/format:
|
|
||||||
plugin: default_value
|
|
||||||
default_value: full_html
|
|
||||||
|
|
||||||
body/0/value: content
|
|
||||||
|
|
||||||
title: title
|
|
||||||
created: created
|
|
||||||
changed: created
|
|
||||||
path: path
|
|
||||||
status: status
|
|
||||||
|
|
||||||
field_excerpt: excerpt
|
|
||||||
|
|
||||||
field_tags:
|
|
||||||
plugin: migration_lookup
|
|
||||||
migration: tag_term
|
|
||||||
source: tags
|
|
||||||
|
|
||||||
type:
|
|
||||||
plugin: default_value
|
|
||||||
default_value: post
|
|
||||||
|
|
||||||
uid:
|
|
||||||
plugin: default_value
|
|
||||||
default_value: 1
|
|
||||||
|
|
||||||
destination:
|
|
||||||
plugin: 'entity:node'
|
|
||||||
|
|
||||||
migration_dependencies:
|
|
||||||
required:
|
|
||||||
- tag_term
|
|
|
@ -1,51 +0,0 @@
|
||||||
id: redirect
|
|
||||||
|
|
||||||
source:
|
|
||||||
plugin: url
|
|
||||||
data_fetcher_plugin: http
|
|
||||||
data_parser_plugin: json
|
|
||||||
|
|
||||||
urls: https://opdavies.netlify.app/redirects.json
|
|
||||||
|
|
||||||
ids:
|
|
||||||
id:
|
|
||||||
type: integer
|
|
||||||
|
|
||||||
item_selector: redirects/
|
|
||||||
|
|
||||||
fields:
|
|
||||||
- name: id
|
|
||||||
selector: id
|
|
||||||
label: Redirect ID
|
|
||||||
|
|
||||||
- name: from
|
|
||||||
selector: from
|
|
||||||
label: From
|
|
||||||
|
|
||||||
- name: to
|
|
||||||
selector: to
|
|
||||||
label: To
|
|
||||||
|
|
||||||
process:
|
|
||||||
redirect_source/path: from
|
|
||||||
redirect_redirect/uri:
|
|
||||||
plugin: opd_redirect
|
|
||||||
source: to
|
|
||||||
|
|
||||||
language:
|
|
||||||
plugin: default_value
|
|
||||||
default_value: und
|
|
||||||
|
|
||||||
status_code:
|
|
||||||
plugin: default_value
|
|
||||||
default_value: 301
|
|
||||||
|
|
||||||
uid:
|
|
||||||
plugin: default_value
|
|
||||||
default_value: 1
|
|
||||||
|
|
||||||
destination:
|
|
||||||
plugin: 'entity:redirect'
|
|
||||||
|
|
||||||
migration_dependencies:
|
|
||||||
required: { }
|
|
|
@ -1,27 +0,0 @@
|
||||||
id: tag_term
|
|
||||||
|
|
||||||
source:
|
|
||||||
plugin: url
|
|
||||||
data_fetcher_plugin: http
|
|
||||||
data_parser_plugin: json
|
|
||||||
urls: https://opdavies.netlify.app/tags.json
|
|
||||||
ids:
|
|
||||||
name:
|
|
||||||
type: string
|
|
||||||
item_selector: tags/
|
|
||||||
fields:
|
|
||||||
-
|
|
||||||
name: id
|
|
||||||
selector: id
|
|
||||||
label: Tag ID
|
|
||||||
-
|
|
||||||
name: name
|
|
||||||
selector: name
|
|
||||||
label: Name
|
|
||||||
|
|
||||||
process:
|
|
||||||
name: name
|
|
||||||
|
|
||||||
destination:
|
|
||||||
plugin: 'entity:taxonomy_term'
|
|
||||||
default_bundle: tags
|
|
|
@ -1,86 +0,0 @@
|
||||||
id: talk_node
|
|
||||||
|
|
||||||
source:
|
|
||||||
plugin: url
|
|
||||||
data_fetcher_plugin: http
|
|
||||||
data_parser_plugin: json
|
|
||||||
|
|
||||||
urls: https://opdavies.netlify.app/talks.json
|
|
||||||
|
|
||||||
ids:
|
|
||||||
id:
|
|
||||||
type: integer
|
|
||||||
|
|
||||||
item_selector: talks/
|
|
||||||
|
|
||||||
fields:
|
|
||||||
- name: id
|
|
||||||
selector: id
|
|
||||||
label: Node ID
|
|
||||||
|
|
||||||
- name: title
|
|
||||||
selector: title
|
|
||||||
label: Title
|
|
||||||
|
|
||||||
- name: description
|
|
||||||
selector: description
|
|
||||||
label: Description
|
|
||||||
|
|
||||||
- name: created
|
|
||||||
selector: created
|
|
||||||
label: Created
|
|
||||||
|
|
||||||
- name: content
|
|
||||||
selector: content
|
|
||||||
label: Content
|
|
||||||
|
|
||||||
- name: path
|
|
||||||
selector: path
|
|
||||||
label: Path
|
|
||||||
|
|
||||||
- name: speakerdeck
|
|
||||||
selector: speakerdeck
|
|
||||||
label: Speakerdeck
|
|
||||||
|
|
||||||
- name: events
|
|
||||||
selector: events
|
|
||||||
label: Events
|
|
||||||
|
|
||||||
- name: video
|
|
||||||
selector: video
|
|
||||||
label: Video
|
|
||||||
|
|
||||||
process:
|
|
||||||
body/0/format:
|
|
||||||
plugin: default_value
|
|
||||||
default_value: full_html
|
|
||||||
|
|
||||||
body/0/value: content
|
|
||||||
|
|
||||||
field_excerpt: description
|
|
||||||
|
|
||||||
title: title
|
|
||||||
created: created
|
|
||||||
changed: created
|
|
||||||
path: path
|
|
||||||
|
|
||||||
field_slides/0/data_id: speakerdeck/id
|
|
||||||
field_slides/0/data_ratio: speakerdeck/ratio
|
|
||||||
|
|
||||||
status:
|
|
||||||
plugin: default_value
|
|
||||||
default_value: 1
|
|
||||||
|
|
||||||
type:
|
|
||||||
plugin: default_value
|
|
||||||
default_value: talk
|
|
||||||
|
|
||||||
uid:
|
|
||||||
plugin: default_value
|
|
||||||
default_value: 1
|
|
||||||
|
|
||||||
destination:
|
|
||||||
plugin: opd_talk
|
|
||||||
|
|
||||||
migration_dependencies:
|
|
||||||
required: { }
|
|
|
@ -1,99 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
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\media\Entity\Media;
|
|
||||||
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;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A migrate destination for a talk node.
|
|
||||||
*
|
|
||||||
* @MigrateDestination(
|
|
||||||
* id="opd_talk"
|
|
||||||
* )
|
|
||||||
*/
|
|
||||||
final 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->createEventParagraphs($row, $node);
|
|
||||||
$this->createVideoMedia($row, $node);
|
|
||||||
|
|
||||||
$node->save();
|
|
||||||
|
|
||||||
return [$node->id()];
|
|
||||||
}
|
|
||||||
|
|
||||||
private function createEventParagraphs(Row $row, EntityInterface $node): void {
|
|
||||||
$eventData = $row->getSourceProperty('events');
|
|
||||||
|
|
||||||
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());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private function createVideoMedia(Row $row, EntityInterface $node): void {
|
|
||||||
$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'];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,29 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Drupal\custom\Plugin\migrate\process;
|
|
||||||
|
|
||||||
use Drupal\migrate\MigrateExecutableInterface;
|
|
||||||
use Drupal\migrate\ProcessPluginBase;
|
|
||||||
use Drupal\migrate\Row;
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Perform custom value transformations.
|
|
||||||
*
|
|
||||||
* @MigrateProcessPlugin(
|
|
||||||
* id = "opd_redirect"
|
|
||||||
* )
|
|
||||||
*/
|
|
||||||
final class OpdRedirect extends ProcessPluginBase {
|
|
||||||
|
|
||||||
public function transform($value, MigrateExecutableInterface $migrateExecutable, Row $row, $destinationProperty) {
|
|
||||||
if (Str::startsWith($value, '/')) {
|
|
||||||
return "internal:{$value}";
|
|
||||||
}
|
|
||||||
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in a new issue