AnswerBun.com

selecting hierarchical select values during migration

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

One Answer

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

Add your own answers!

Related Questions

File field upload in modal/dialog

1  Asked on December 4, 2020 by ctrnz

     

How to pre-select items in a select with chosen

1  Asked on December 3, 2020 by jav

 

Update existing node (not created by Migrate) via Migrate 8.5.x

1  Asked on December 3, 2020 by vaibhav-rana

 

Secondary Tabs and views

1  Asked on December 2, 2020 by timwhelan

 

alter Suggestion box for apache solr autosearch

2  Asked on December 1, 2020 by anamika

   

User specific permission to add links to a menu

2  Asked on November 26, 2020 by mavicc

 

How to alter sort handler to keep existing order intact in views

1  Asked on November 18, 2020 by hiranya-sarma

   

Issue using Config Split on content types

0  Asked on November 18, 2020 by vecta

   

How to create simple confirmation page?

3  Asked on November 11, 2020 by mathewdragon

 

How do I add a template suggestion for a Views block?

2  Asked on October 21, 2020 by wbeasley

       

How to programmatically manage taxonomies?

1  Asked on October 15, 2020 by deny-dias

   

CSS-tags added using Display suite on products disappears

1  Asked on October 4, 2020 by anders-wallenquist

 

I have issue with commerce_order_load_multiple function

1  Asked on October 1, 2020 by user3686276

 

Why can’t I install even if I have the required PHP version?

0  Asked on September 13, 2020 by hendrik-kaiser

 

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP