I'm writing a migrate source plugin for migrating D7 entityform (entityform module) submissions. If anyone has done this or knows an existing plugin, please let me know.
I am trying to extend the FieldableEntity
base class from Drupal\migrate_drupal\Plugin\migrate\source\d7\FieldableEntity;
because I want to use its getFields()
and getFieldValues()
methods when I override prepareRow()
to include custom fields from my D7 entityform.
My problem is that when my source plugin extends FieldableEntity
, drush reports [error] No migrations found.
for my migration. Importantly, however, if my source plugin instead uses the SqlBase
class from Drupal\migrate\Plugin\migrate\source\SqlBase
, then drush can import all of my entityforms from D7 into D9 contact forms no problem. So it would seem that I am missing something when I try to implement FieldableEntity
preventing it from retrieving data for the migration.
Here is my plugin, which shows up fine in drush ms
:
<?php
namespace Drupal\mymodule_migrate\Plugin\migrate\source;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\d7\FieldableEntity;
/**
* The 'mymodule_migrate_entityform' source plugin.
*
* @MigrateSource(
* id = "mymodule_migrate_entityform",
* source_module = "mymodule_migrate"
* )
*/
class Entityform extends FieldableEntity {
/**
* {@inheritdoc}
*/
public function query() {
$query = $this->select('entityform', 'e')
->fields('e', [
'entityform_id',
'type',
'created',
'changed',
'uid'
]);
return $query;
}
/**
* {@inheritdoc}
*/
public function fields() {
return array(
'entityform_id' => $this->t('The ID of the entityform submission.'),
'type' => $this->t('The entityform type.'),
'created' => $this->t('The time that the entityform was submitted.'),
'changed' => $this->t('Last updated time.'),
'uid' => $this->t('The {users}.uid who submitted the entityform. If set to 0, this entityform was submitted by an anonymous user.'),
);
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['entityform_id']['type'] = 'integer';
$ids['entityform_id']['alias'] = 'e';
return $ids;
}
/**
* {@inheritdoc}
*/
public function prepareRow(Row $row) {
$entityform_id = $row->getSourceProperty('entityform_id');
// Get Field API field values.
foreach ($this->getFields('entityform', 'BUNDLE_MACHINE_NAME') as $field_name => $field) {
$row->setSourceProperty($field_name, $this->getFieldValues('entityform', $field_name, $entityform_id));
}
return parent::prepareRow($row);
}
}
I use this yml migration definition. My migrate destination is D8/D9 contact_message entity.
id: mymodule_contact_message
label: D8 Contact message migration from D7 entityform submission
source:
plugin: mymodule_migrate_entityform
process:
id: entityform_id
langcode:
plugin: default_value
source: language
default_value: "und"
created: created
changed: changed
destination:
plugin: entity:contact_message
default_bundle: MY_DESTINATION_BUNDLE
As stated above, all of this works great when I use SqlBase
in my plugin. But with FieldableEntity
drush comes back with [error] No migrations found.
\Drupal\[module]\Plugin\migrate\source\d7