Drupal Answers Asked by nitvirus on December 9, 2020
I want to select the values of a taxonomy which is being shown by heirachical select. These values are to be selected while importing the data through csv by using migration module.
right now i am passing the values but it not picking up the hierarchical select list.
Any help would be useful..
thanks
Dunno why my last message has been deleted but well I founded the answer alone : In order To make it work, you have to pass an array of values containing the terms tid values and their parent's tid. You might have to use a callback that retrieve the parent tid from the children one.
I am migrating contents from drupal 6 to 7, not from a csv, but I've declared a static function containing the mapping between the old tids and the new ones like so :
public static $hierarchicalThemesToTheme1TidsMap = array(
'1' => array('tid' => '13', 'parent' => '0'),
'1797' => array('tid' => '14', 'parent' => '13'),
'14993' => array('tid' => '15', 'parent' => '13'),
'1801' => array('tid' => '16', 'parent' => '13'),
'59' => array('tid' => '17', 'parent' => '13'),
'1795' => array('tid' => '18', 'parent' => '13'),
'1796' => array('tid' => '19', 'parent' => '13'),
'1798' => array('tid' => '24', 'parent' => '13'),
'1799' => array('tid' => '23', 'parent' => '13'),
'1811' => array('tid' => '42', 'parent' => '0'),
'1812' => array('tid' => '42', 'parent' => '0'),
'1813' => array('tid' => '42', 'parent' => '0'),
'1800' => array('tid' => '20', 'parent' => '42'),
'1802' => array('tid' => '21', 'parent' => '42'),
'1803' => array('tid' => '22', 'parent' => '42'),
'1804' => array('tid' => '18', 'parent' => '13'),
'1805' => array('tid' => '18', 'parent' => '13'),
'62' => array('tid' => '25', 'parent' => '0'),
'1806' => array('tid' => '26', 'parent' => '25'),
'1807' => array('tid' => '27', 'parent' => '25'),
'64' => array('tid' => '28', 'parent' => '25'),
'1808' => array('tid' => '29', 'parent' => '25'),
'1809' => array('tid' => '30', 'parent' => '25'),
'61' => array('tid' => '32', 'parent' => '0'),
'1723' => array('tid' => '33', 'parent' => '32'),
'1724' => array('tid' => '34', 'parent' => '32'),
'1725' => array('tid' => '35', 'parent' => '32'),
'1726' => array('tid' => '36', 'parent' => '32'),
'1727' => array('tid' => '37', 'parent' => '32'),
'1728' => array('tid' => '38', 'parent' => '32'),
'1729' => array('tid' => '39', 'parent' => '32'),
'1730' => array('tid' => '40', 'parent' => '32'),
'1731' => array('tid' => '41', 'parent' => '32'),
'1810' => array('tid' => '43', 'parent' => '13'),
'4401' => array('tid' => '44', 'parent' => '13'),
);
I had to do that because we didn't use migrate for the taxonomies. I guess there's a better way if you had use migrate to import your taxonomies.
Then I've declared a callback which use that static array to retrieve the tids and their parent tid :
public function getHierarchicalThemeByTids($tids) {
$mapped_tids = array();
foreach($tids as $tid) {
$mapped_tid = FOMigration::getMappedId(self::$hierarchicalThemesToTheme1TidsMap, $tid, NULL);
if($mapped_tid !== NULL) {
$mapped_tids[] = $mapped_tid['tid'];
if (!in_array($mapped_tid['parent'], $mapped_tids)) {
$mapped_tids[] = $mapped_tid['parent'];
}
}
}
return $mapped_tids;
}
Finally I just tell migrate he has to use that callback to get the values :
$this->addFieldMapping('field_types', 'field_theme')->callbacks(array($this, 'getHierarchicalThemeByTids'));
$this->addFieldMapping('field_types:source_type')->defaultValue('tid');
Answered by MacSim on December 9, 2020
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP