Created
June 16, 2016 19:01
-
-
Save boolboost/6039ade9386f222e49e8132c6b2c91cf to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* Implements hook_entity_insert(). | |
*/ | |
function hook_entity_insert($entity, $type) { | |
$bundle = isset($entity->type) ? $entity->type : '*'; | |
// new entity | |
if (isset($entity->is_new) && $entity->is_new) { | |
if (isset($_GET['id']) && is_numeric($_GET['id']) && isset($_GET['type'])) { | |
$target_id = intval($_GET['id']); | |
$target_type = $_GET['type']; | |
// Add join with parent entity | |
switch ("{$type}:{$bundle}") { | |
case 'departure:departure': | |
$wrapper = entity_metadata_wrapper($target_type, $target_id); | |
if (isset($wrapper->field_ref_departures)) { | |
$wrapper->field_ref_departures[] = $entity->id; | |
} | |
$wrapper->save(); | |
break; | |
} | |
} | |
} | |
crm__entity_save($entity, $type); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment