View source
<?php
namespace Drupal\course_migrate\Plugin\migrate\source;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\d7\FieldableEntity;
class Course extends FieldableEntity {
public function getIds() {
$ids = [];
$ids['nid']['type'] = 'integer';
$ids['nid']['alias'] = 'n';
return $ids;
}
public function query() {
$query = $this
->select('course_node', 'c');
$query
->join('node', 'n', 'n.nid = c.nid');
$query
->fields('c');
$query
->fields('n', [
'nid',
'vid',
'title',
'uid',
'created',
'changed',
'type',
'status',
]);
if (isset($this->configuration['bundle'])) {
$query
->condition('n.type', (array) $this->configuration['bundle'], 'IN');
}
return $query;
}
public function fields() {
return [
'nid' => 'Node ID',
'title' => 'Title',
'type' => 'Course type',
'outline' => 'Outline type',
'credits' => 'Credits',
'open' => 'Open',
'close' => 'Close',
'duration' => 'Duration',
'external_id' => 'External ID',
'enrollment_type' => 'Enrollment type for new enrollments',
'relationships' => 'Relationships data',
'created' => 'Created',
'changed' => 'Changed',
];
}
public function prepareRow(Row $row) {
$nid = $row
->getSourceProperty('nid');
$vid = $row
->getSourceProperty('vid');
$type = $row
->getSourceProperty('type');
foreach ($this
->getFields('node', $type) as $field_name => $field) {
$row
->setSourceProperty($field_name, $this
->getFieldValues('node', $field_name, $nid, $vid));
}
return parent::prepareRow($row);
}
}