Last active
August 29, 2015 14:26
-
-
Save cogentParadigm/5a7fd247b510ec2a283a to your computer and use it in GitHub Desktop.
UIF Tac Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function custom_behaviors_uif_post_create($account, $user_data, $form_state) { | |
custom_behaviors_after_user_import($account, $user_data, $form_state); | |
} | |
function custom_behaviors_uif_post_update($account, $user_data, $form_state) { | |
custom_behaviors_after_user_import($account, $user_data, $form_state); | |
} | |
function custom_behaviors_after_user_import($account, $user_data, $form_state) { | |
$edit['tac_lite'] = array(); | |
$regions_vocab = taxonomy_vocabulary_machine_name_load("txn_regions")->vid; | |
$institutions_vocab = taxonomy_vocabulary_machine_name_load("txn_institutions")->vid; | |
$newsletter_vocab = taxonomy_vocabulary_machine_name_load("newsletter")->vid; | |
$microsite_vocab = taxonomy_vocabulary_machine_name_load("microsite")->vid; | |
static $alls = array(); | |
if (empty($alls)) { | |
$alls[$regions_vocab] = array(0); | |
$alls[$institutions_vocab] = array(); | |
$alls[$newsletter_vocab] = array(); | |
$alls[$microsite_vocab] = array(); | |
foreach ($alls as $idx => $value) { | |
$tree = taxonomy_get_tree($idx); | |
foreach ($tree as $term) { | |
$value[] = $term->tid; | |
} | |
$alls[$idx] = $value; | |
} | |
} | |
if (!empty($user_data['regions'])) { | |
if ($user_data['regions'] === "All") $edit['tac_lite'][$regions_vocab] = $alls[$regions_vocab]; | |
else { | |
$edit['tac_lite'][$regions_vocab] = array(); | |
$regions = explode(",", $user_data['regions']); | |
foreach ($regions as $r) { | |
if ($r == "Canada") $t = 0; | |
else { | |
$t = taxonomy_get_term_by_name($r, "txn_regions"); | |
$t = array_shift($t['taxonomy_term'])->tid; | |
} | |
$edit['tac_lite'][$regions_vocab][] = $t; | |
} | |
} | |
} | |
if (!empty($user_data['institutions'])) { | |
if ($user_data['institutions'] === "All") $edit['tac_lite'][$institutions_vocab] = $alls[$institutions_vocab]; | |
else { | |
$edit['tac_lite'][$institutions_vocab] = array(); | |
$items = explode(",", $user_data['institutions']); | |
foreach ($items as $r) { | |
$t = taxonomy_get_term_by_name($r, "txn_institutions"); | |
$t = array_shift($t['taxonomy_term'])->tid; | |
$edit['tac_lite'][$institutions_vocab][] = $t; | |
} | |
} | |
} | |
if (!empty($user_data['newsletters'])) { | |
if ($user_data['newsletters'] === "All") $edit['tac_lite'][$newsletter_vocab] = $alls[$newsletter_vocab]; | |
else { | |
$edit['tac_lite'][$newsletter_vocab] = array(); | |
$items = explode(",", $user_data['newsletters']); | |
foreach ($items as $r) { | |
$t = taxonomy_get_term_by_name($r, "newsletter"); | |
$t = array_shift($t['taxonomy_term'])->tid; | |
$edit['tac_lite'][$newsletter_vocab][] = $t; | |
} | |
} | |
} | |
if (!empty($user_data['microsites'])) { | |
if ($user_data['microsites'] === "All") $edit['tac_lite'][$microsite_vocab] = $alls[$microsite_vocab]; | |
else { | |
$edit['tac_lite'][$microsite_vocab] = array(); | |
$items = explode(",", $user_data['newsletters']); | |
foreach ($items as $r) { | |
$t = taxonomy_get_term_by_name($r, "microsite"); | |
$t = array_shift($t['taxonomy_term'])->tid; | |
$edit['tac_lite'][$microsite_vocab][] = $t; | |
} | |
} | |
} | |
user_save($account, $edit, 'tac_lite'); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment