Given a source that has a field with the corresponding ID which outputs the id in the field special like the field nid gives back a node id.

I want to map it to a taxonomy term that is already existing on the new site and not migrated.

This is the process part of my custom yml file:

  nid: nid
  vid: vid
  # there were some more fields here that I left out.
  # hardcode destination node type as publication
    plugin: default_value
    default_value: publication
  # custom fields
    plugin: static_map
    source: special
      1: 1
      2: 2
      3: 3

I have a field_special as taxonomy term reference field in the node I want to migrate to.

How can I map the source field to be used in the destination field which is a taxonomy term reference field?

I'm using Drupal 8.1.2 with migrate_plus migrate_tools migrate_drupal enabled.

  • Can you add snippets to sample data you are using?
    – Eyal
    Commented Jun 19, 2016 at 18:56
  • And are you using Drupal 8.1 or 8.0 (or 8.2)?
    – Eyal
    Commented Jun 19, 2016 at 18:57
  • Also, are you using the migrate_plus module?
    – Eyal
    Commented Jun 19, 2016 at 19:39

1 Answer 1


I've rewritten my yml to use:

  plugin: iterator
  source: field_special
    target_id: tid

And written a preparerow function in my class to output an array as source property:

   * {@inheritdoc}
  public function prepareRow(Row $row) {
    $nid = $row->getSourceProperty('nid');

    $result = $this->getDatabase()->query(
        GROUP_CONCAT(field_special_tid) as tids
        {field_data_field_special} fs
        fs.entity_id = :nid
      array(':nid' => $nid)
    foreach ($result as $record) {
      if (!is_null($record->tids)) {
        $row->setSourceProperty('special', explode(',', $record->tids));
    return parent::prepareRow($row);

This workaround will do for now, but if you have a better answer please post so I can accept your answer.

  • 1
    Your solution seems the way to go. The only issue is the format in which you queried the database.
    – Eyal
    Commented Jun 19, 2016 at 19:54
  • The query works, Tough it could be nicer but since it's a migration script I didn't care to use a entity field query.
    – FLY
    Commented Jun 20, 2016 at 8:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.