Include the tags field migration.

This commit is contained in:
David Valdez 2018-10-30 12:33:04 -06:00
parent 77c6286dbb
commit 1794c62709
2 changed files with 53 additions and 1 deletions

View file

@ -2,7 +2,7 @@ id: agaric_blog
migration_group: agaric migration_group: agaric
label: Agaric Blog label: Agaric Blog
source: source:
plugin: d7_node plugin: agaric_node
node_type: blog node_type: blog
destination: destination:
plugin: entity:node plugin: entity:node
@ -61,6 +61,18 @@ process:
plugin: migration_lookup plugin: migration_lookup
source: node_uid source: node_uid
migration: agaric_people migration: agaric_people
field_tags:
plugin: sub_process
source: field_tags_names
process:
target_id:
- plugin: entity_generate
source: name
value_key: name
bundle_key: vid
bundle: tags
entity_type: taxonomy_term
ignore_case: true
migration_dependencies: migration_dependencies:
required: required:
- agaric_people - agaric_people

View file

@ -0,0 +1,40 @@
<?php
namespace Drupal\agaric_migration\Plugin\migrate\source;
use Drupal\migrate\Row;
use Drupal\node\Plugin\migrate\source\d7\Node;
/**
* Add the Taxonomy term name in the query.
*
* This adds the sourceProperty field_tags_names which are the name of the terms
*
* @MigrateSource(
* id = "agaric_node",
* source_module = "node"
* )
*/
class AgaricNode extends Node {
public function prepareRow(Row $row) {
$nid = $row->getSourceProperty('nid');
// Get the taxonomy tags names.
$tags = $this->getFieldValues('node', 'field_tags', $nid);
$names = [];
foreach ($tags as $tag) {
$tid = $tag['tid'];
$query = $this->select('taxonomy_term_data', 't');
$query->condition('tid', $tid);
$query->addField('t', 'name');
$result = $query->execute()->fetchAssoc();
$names[] = ['name' => $result['name']];
}
$row->setSourceProperty('field_tags_names', $names);
return parent::prepareRow($row);
}
}