You are here

function crm_core_relationship_ui_add_relationship in CRM Core 8

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.2 modules/crm_core_relationship_ui/crm_core_relationship_ui.pages.inc \crm_core_relationship_ui_add_relationship()
  3. 7 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 203
CRM Core Relationship UI Pages.

Code

function crm_core_relationship_ui_add_relationship($contact) {
  drupal_set_title(t('Add a relationship'));
  $relationship_type_links = [];
  if ($contact) {
    _crm_core_relationships_ui_breadcrmub($contact);
    foreach ([
      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] = [
            'title' => $title,
            'href' => $href,
            'localized_options' => [],
            'description' => t('Create %kind relationship.', [
              '%kind' => $title,
            ]),
          ];
        }
      }
    }
  }
  else {
    foreach ([
      0,
      1,
    ] as $reverse) {
      foreach (ContactType::loadActive() 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[] = [
              'title' => $title,
              'href' => $href,
              'localized_options' => [],
              'description' => t('Create %kind relationship.', [
                '%kind' => $title,
              ]),
            ];
          }
        }
      }
    }
  }
  $return = '';
  if (!empty($relationship_type_links)) {
    $return = theme('crm_core_contact_add_list', [
      'content' => $relationship_type_links,
    ]);
  }
  return $return;
}