EntityLegalDocumentVersion.php in Entity Legal 3.0.x
File
src/Plugin/migrate/source/EntityLegalDocumentVersion.php
View source
<?php
namespace Drupal\entity_legal\Plugin\migrate\source;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\d7\FieldableEntity;
class EntityLegalDocumentVersion extends FieldableEntity {
public function query() {
$query = $this
->select('entity_legal_document_version', 'v')
->fields('v');
$query
->join('entity_legal_document', 'd', 'v.document_name = d.name');
$query
->addExpression('IF(d.published_version = v.vid, 1, 0)', 'published');
return $query;
}
public function fields() {
return [
'name' => $this
->t('The entity ID of this document.'),
'document_name' => $this
->t('The name of the document this version is bound to.'),
'label' => $this
->t('The title of the document.'),
'published' => $this
->t('Published'),
'acceptance_label' => $this
->t('Acceptance label'),
'created' => $this
->t('The date the document was created.'),
'updated' => $this
->t('The date the document was changed.'),
];
}
public function getIds() {
$ids['name']['type'] = 'string';
return $ids;
}
public function prepareRow(Row $row) {
foreach (array_keys($this
->getFields('entity_legal_document_version', $row
->getSourceProperty('document_name'))) as $field) {
$name = $row
->getSourceProperty('vid');
$row
->setSourceProperty($field, $this
->getFieldValues('entity_legal_document_version', $field, $name));
}
return parent::prepareRow($row);
}
}