I solved this the following was
I first installed the below extensions on civicrm
- Entity Settings Helper Extension
- Related Permissions Module
Then I created a relationship
- GOTO /civicrm/admin/reltype?reset=1
- Click on Add Relationship Type and add the relationship. Make sure you check the Always Permission A to B check box
The next step is to create a Drupal module that will add the above created relationship to the new contact and the creator of the contact. We need to just use on hook to get this done. The code has the relationship ID hard coded but it works :)
/**
* Implements hook_civicrm_post
*/
function crc_civicrm_creator_relate_civicrm_post($op, $objectName, $objectId, &$objectRef) {
if (!civicrm_initialize()) {
return;
}
if ($objectName == "Individual" && $op == 'create') {
global $user;
$userObj = user_load($user->uid);
// Get the email of the current logged in user
$emailObj = civicrm_api3('Email', 'get', [
'sequential' => 1,
'email' => $userObj->mail,
]);
//Create a relationship between the current user and the created
// individual contact
$result = civicrm_api3('Relationship ', 'create', [
'sequential' => 1,
'contact_id_a' => $emailObj['values'][0]['contact_id'],
'contact_id_b' => $objectId,
'relationship_type_id' => 11,
]);
}
}
THATS IT. Now enable the module and create your contacts and you will also be able to search view and edit them.