MigrateDestinationTerm

Last updated on
30 April 2025

To migrate content into Drupal taxonomy terms, use the MigrateDestinationTerm class:

$term_options = MigrateDestinationTerm::options($language, $text_format);
$this->destination = new MigrateDestinationTerm('tags', $term_options);
$this->addFieldMapping('name', 'source_name');
...

The first argument is the bundle (vocabulary machine_name) you wish to migrate source content into.

Fields

tid - The Drupal term ID. Usually this will be unmapped - the tid will be automatically assigned when the term is created, and the map table will record the source key that generated this ID. You would map the tid when the system-of-record is DESTINATION (i.e., the purpose of your migration is updating existing terms rather than importing new terms). Note also, tids cannot be created on an initial migration. Drupal does not allow for specifying term ids upon creation. If this is tried then no error will be thrown, instead Migrate will say that everything updated just fine. However, no data will be inserted and you may need to manually truncate the migrate_map_[machine name] table. See http://drupal.org/node/1516244 for explanation.

name - The name of the term. If a term of the name (and in the same place in a hierarchical vocabulary) already exists, then the incoming term is mapped to the existing term.

description - The term description.

parent - The Drupal term ID of the term's parent, typically mapped using sourceMigration($this->machineName). Mutually exclusive with parent_name.

parent_name - The name of the term's parent. Mutually exclusive with parent.

format - The text format (e.g., 'Filtered HTML') associated with the description.

weight - The weight of the term (i.e., its default ordering in listings of terms).

Options

Language

The language option will be applied as the default language for any term fields which are language-dependent. If unspecified, it will default to LANGUAGE_NONE.

Text format

The text format (e.g., 'filtered_html') will be applied as the default text format for any term fields which take a format. If unspecified, the default for the field will be applied.

Allowed duplicated terms

By default this setting is set to false. If you import two (or more) terms with the same name, migrate will treat them as one term. From migrate point of view you will get one create and one update for same term.

If set to true, migrate will create two terms even if they have the same name. From migrate point of view you will get two creates.

For Migrate 2.6 add to MigrateDestinationTerm this option:
'allow_duplicate_terms' => TRUE

Advanced usage

The vocabulary passed to the MigrateDestinationTerm constructor can be overridden on a per-term basis by mapping vocabulary_machine_name:

  $this->addFieldMapping('vocabulary_machine_name', 'category_name');

See also Advanced field mapping for Migrate wizard UI help.

Help improve this page

Page status: Not set

You can: