0

I am trying to merging content types while migrating to drupal 8 from drupal 7 and at the same time differentiating them with the taxonomy terms in D8. E.g. The content types from D7 i.e. Article, Page, Blog will merge to a content types called "Media" in D8. But in D8 "Media" content type, there will be a vocabulary "Type of content" with terms as Article, Page and Blog, so that while migrating from D7, the content of Article will be tagged to "Article" term in "Media" content type and same for others.

I am able to merge them to single content type in D8, by giving destination plugin for each content type as -

destination:
  plugin: 'entity:node'
  default_bundle: media

but not able to figure out how to tagged with "Type of content" vocabulary. This is additional field which is present in D8 but not in D7.

I tried to add

$row->setSourceProperty('field_type_of_content', $type_of_content);
$row->setDestinationProperty('field_type_of_content', $type_of_content);

code in hook_migrate_prepare_row() but not working...

Any suggestion. Thanks in Advance.

Regards Sunil Singh

0

field_type_of_content is presumably a term reference field, so the value to set for it would be a term ID, not a term name. If you know the IDs for the destination terms, you can map them directly:

source:
  plugin: d7_node
  node_type: article
process:
  field_type_of_content:
    plugin: default_value
    default_value: 5   # Known D8 ID for the "Article" term

More robustly, you can use migrate_plus's entity_lookup plugin to translate the term name to a term ID:

source:
  plugin: d7_node
  node_type: article
  constants:
    term_name: Article
process:
  field_type_of_content:
    plugin: entity_lookup
    source: constants/term_name
    value_key: name
    entity_type: taxonomy_term
    bundle: type_of_content
    bundle_key: vid

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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