Skip to content

Instantly share code, notes, and snippets.

@boolboost
Created June 16, 2016 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boolboost/6039ade9386f222e49e8132c6b2c91cf to your computer and use it in GitHub Desktop.
Save boolboost/6039ade9386f222e49e8132c6b2c91cf to your computer and use it in GitHub Desktop.
/**
* 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