You are here

function crm_core_relationship_ui_add_relationship in CRM Core 7

Same name and namespace in other branches
  1. 8.3 modules/crm_core_relationship_ui/crm_core_relationship_ui.pages.inc \crm_core_relationship_ui_add_relationship()
  2. 8 modules/crm_core_relationship_ui/crm_core_relationship_ui.pages.inc \crm_core_relationship_ui_add_relationship()
  3. 8.2 modules/crm_core_relationship_ui/crm_core_relationship_ui.pages.inc \crm_core_relationship_ui_add_relationship()

Return a list of links to add relationship for specific CRM contact.

Parameters

$contact: Entity object of crm_core_contact type.

1 string reference to 'crm_core_relationship_ui_add_relationship'
crm_core_relationship_ui_menu in modules/crm_core_relationship_ui/crm_core_relationship_ui.module
Implements hook_menu().

File

modules/crm_core_relationship_ui/crm_core_relationship_ui.pages.inc, line 182

Code

function crm_core_relationship_ui_add_relationship($contact) {
  drupal_set_title(t('Add a relationship'));
  $relationship_type_links = array();
  if ($contact) {
    _crm_core_relationships_ui_breadcrmub($contact);
    foreach (array(
      0,
      1,
    ) as $reverse) {
      $relationship_types = crm_core_relationship_load_relationship_types($contact->type, $reverse);
      foreach ($relationship_types as $relationship_type) {
        if (user_access('create relation entities of bundle ' . $relationship_type->relation_type) || user_access('create relation entities of any contact relationship')) {
          $contact_uri = $contact
            ->uri();
          $href = $contact_uri['path'] . '/relationships/add/' . $relationship_type->relation_type . '/' . $reverse;
          $title = $reverse ? $relationship_type->reverse_label : $relationship_type->label;
          $relationship_type_links[$relationship_type->relation_type] = array(
            'title' => $title,
            'href' => $href,
            'localized_options' => array(),
            'description' => t('Create %kind relationship.', array(
              '%kind' => $title,
            )),
          );
        }
      }
    }
  }
  else {
    foreach (array(
      0,
      1,
    ) as $reverse) {
      foreach (crm_core_contact_types(TRUE) as $contact_type) {
        $relationship_types = crm_core_relationship_load_relationship_types($contact_type->type, $reverse);
        foreach ($relationship_types as $relationship_type) {
          if (user_access('create relation entities of bundle ' . $relationship_type->relation_type) || user_access('create relation entities of any contact relationship')) {
            $href = 'crm-core/contact/relationship-add/' . $relationship_type->relation_type . '/' . $reverse;
            $title = $reverse ? $relationship_type->reverse_label : $relationship_type->label;
            $relationship_type_links[] = array(
              'title' => $title,
              'href' => $href,
              'localized_options' => array(),
              'description' => t('Create %kind relationship.', array(
                '%kind' => $title,
              )),
            );
          }
        }
      }
    }
  }
  $return = '';
  if (!empty($relationship_type_links)) {
    $return = theme('crm_core_contact_ui_add_list', array(
      'content' => $relationship_type_links,
    ));
  }
  return $return;
}